Set the index in setEditorData().
Do you mean this?
Qt Code:
{ comboBox->setCurrentIndex( 1 ); // comboBox->setCurrentIndex(comboBox->findText(index.data().toString())); }To copy to clipboard, switch view to plain text mode
In this way the combo box will not show any changes that occur in the database..it will always show index 1.
Is there a way to do it in the createEditor function?
Uncomment line #6 in your code and change the findText() part to something that detects if the string in the model is present in the combobox before you blindly set it on the combo.
I am sorry but I did not understand your correction.Uncomment line #6 in your code and change the findText() part to something that detects if the string in the model is present in the combobox before you blindly set it on the combo.
The combo has three items:
Qt Code:
editor->addItem("a"); editor->addItem("b56"); editor->addItem("cc");To copy to clipboard, switch view to plain text mode
When the program starts running I would like the combo to show the first item "a" instead of blank.
Then the user can choose any item s/he wishes.
Is there a way to initialize the combo to item "a"?
The combobox has to show whatever data is in the model for the current cell and not what you want. You can say that if the model doesn't return data for an index, "a" should be set as the combobox current item. But then the model will never contain "a" (or its equivalent) unless you first change the combobox to something else, close the editor, reopen it again and change the cell back to "a".
I have been working on the same thing. Like wysota said, the combobox has to show whatever data is in the model for the current cell. to initialise the combobox to 'a', set the value in the model to 'a'. Then in the setEditorData() function you can retrieve the value in the model using something like this.
Qt Code:
To copy to clipboard, switch view to plain text mode
Then you can set the current index like you have previously.
Qt Code:
comboBox->setCurrentIndex(comboBox->findText(value));To copy to clipboard, switch view to plain text mode
Bookmarks