How to choose in which QLineEdit should my text put in - c++

I'm working on a project where i have some qpushbuttons and some QlineEdit using qt c++. I want to choose in which QLineEdit my text should be appear. As far I put some text only in the first QLineEdit and the other is filled by condition depending on the first

QInputDialog is a way to get user input.
And I think you need QInputDialog::getItem to choice one of many things.

Related

Make a QDialog read only, but still with text selectable

Disclaimer: I'm not a Qt programmer, I'm just asking in case someone could solve an issue about DB Browser for SQLite.
So, an EditDialog widget is extending the QDialog class. As described in the issue, in some scenarios this widget is readonly, but it would be great if its text content could still be selectable.
There are two use cases:
text selection with the mouse
blinking caret, text selection with keyboard Shift + arrows
The current solution fixes only the first case. There is no blinking caret and keyboard selection doesn't work. Could this be improved?
Assuming the textarea is a QTextEdit or QPlainTextEdit, you should be able to fix this by adjusting the text interaction flags. Try something like this:
ui->editorText->setTextInteractionFlags(
Qt.TextSelectableByMouse | Qt.TextSelectableByKeyboard)

Proper way to find out which Tab of QTabWidget is currently selected

I have a QTabWidget with several tabs, every tab containing a QTableWidget with numbers. Outside of this QTabWidget, I have one button. When the button is pressed, the currently selected widget should be processed. The QTableWidgets are identical in their structure, they just display numbers, and if I have a pointer to one of these widgets, I cannot deduce which tab it came from.
A simple method to identify which widget is currently selected is to call currentIndex(). But this will break when I reorder the tabs in the designer and is probably not working with movable tabs.
Another way is to use currentIndex() and tabText(int index). Like this I have a stable way to find out which tab is currently selected. The disadvantage of this is that I am then dependent on having unique tab texts, and I in general don't like to rely on a UI property to implement functionality.
My solution for now is to give every Widget a different accessible name that I can then read out like this:
QWidget* widget = tabWidget->currentWidget();
QString* name = widget->accessibleName();
This works, but I wonder if there is a better solution, something like the Qt::UserRole that can be assigned to any cell in a QTableWidget.

QTextEdit auto text finisher

Is there any QT class for creation text finisher (If I type "hel", it will automatically finished word with "lo")? Sorry for bad terminology, I don't know how to describe it better.
There is QCompleter but that works an QLineEdit and QComboBox by default only. I never used it but I suppose it should be possible to attach it to a customized QTextEdit too.
Maybe google with QCompleter and QTextEdit as keywords.

QTreeView: How to put multiple widgets in one cell?

I'd like to put multiple widgets in one cell of a QTreeView. QTreeView already does this with check boxes (e.g if you set ItemIsUserCheckable and ItemIsEditable). For example, how would I show a small tool button next to a line edit, instead of the check box next to the line edit?
I've gone through the whole deal of subclassing Qtreeview, implementing a custom ItemDelegate, and overriding paint( ) and createEditor( ). And that works if I only need to render simple things, like a single line edit, single button, etc. However, I cannot get it to work for nested components.
I tried to create a QHBoxLayout, add a QLineEdit and a QToolBarButton to it, add the layout to a new QWidget, and return the whole thing from createEditor( ). However, nothing shows up.
Can anybody provide a simple example?
Thanks!

Qt - How to do superscripts and subscripts in a QLineEdit?

I need to have the ability to use superscripts asnd subscripts in a QLineEdit in Qt 4.6. I know how to do superscripts and subscripts in a QTextEdit as seen below but I can't figure out how to do them in QLineEdit because the class doesn't contain a mergeCurrentCharFormat() function like QTextEdit does. Please help. Thanks
void MainWindow::superscriptFormat()
{
QTextCharFormat format;
format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
if(ui->txtEdit->hasFocus())
ui->txtEdit->mergeCurrentCharFormat(format);
}
QLineEdit wasn't really made for this type of thing, as it was designed for simple text entry. You have a few options, however. The simplest one is to do as Hostile Fork suggested and use a QTextEdit, and add a style override to not show the scroll bar (which I assume would remove the arrows). The more complex one would be to either inherit QLineEdit and do your own drawing, or to make your own widget completely that appears similar to the QLineEdits do.