QSqlQueryModel can not be editable
from docs
The QSqlQueryModel class provides a read-only data model for SQL result sets.
QSqlQueryModel can not be editable
from docs
The QSqlQueryModel class provides a read-only data model for SQL result sets.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Dear Sprit
Problem is, I dont want that to be editable. And yes you are correct it is not editable.
But if I change the combo editable, if user change the curser with tab, it doesnt get the id for the country
Subclass QComboBox and filter key press event. Save the current "search string" in a member variable and perform the search in your QSqlQueryModel or jump to the matching item. Use QTimer to terminate the elapsed time while last key press and clear your internal string if necessary.
was little bit complex?
Something like that:
Qt Code:
// QTime m_time; // QString m_search; { if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down /* || ... */) else { if (m_time.elapsed() > 10) m_search.clear(); m_search.append(event->text()); m_time.restart(); performSearch(); // handles the selection chance of the box according to m_search via setting the querymodel or use QComboBox::findText } }To copy to clipboard, switch view to plain text mode
I would made a little bit simpler
Qt Code:
{ if (text.isEmpty()) else { if (m_time.elapsed() > 10) m_search.clear(); m_search.append(text); m_time.restart(); performSearch(); // handles the selection chance of the box according to m_search via setting the querymodel or use QComboBox::findText }To copy to clipboard, switch view to plain text mode![]()
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
is this possible if I promote this from designer?
Of course. Just use a normal QComboBox and promote it to MyComboBox. If you want a working combo box in your designer preview you have to write a designer plugin with MyComboBox.
Dear all
I think this will not solve my problem. Because,
My combo cant be editable.
My main problem is, I got combo box in a widget or in a delegate, and in the combo boxes I have lots of rows. And every row get an ID from sql when I load the combo.
Like 'country name', and ID, I save these ID to the database. Problem is If I leave the combo not editable, it take to much time to find it in the combo, because there is no write delay, I mean you have to write really fast to do that.
If I make it editable, if users passes the combo without pressing return, the ID doesnt change but the text seems to be changed, so the users cant write it on the database
This problem is my main problem in this project!
Is setEditable(false) blocking the keyPressEvent??? Don't get your problem. If you think finding a item in the box takes to long time (blocks your GUI) use a thread for it. But really a combo box can't be too huge.
let me tell you
like in combo I have 2000 items
let me tell you country name and ids,
I make the combo editable, in that case I could write and find in combo, but in that case if the users passes the combo without pressing return key, the id doesnt change, it stays the old id
A normal CPU says: haha, that's no size for me...So finding items won't take long l'time
You don't need to set the box ediatable. Then user can navigate to the item also by typing. To avoid too short "input cleaning time" use the solution mentioned above.I make the combo editable, in that case I could write and find in combo,
An editable combo box doesn't intend to provide a solution to your problem. Your need can better be fitted by an QLineEdit with an installed QCompleter holding the countries. Or a QlineEdit as search fiel over an QListView etc...but in that case if the users passes the combo without pressing return key, the id doesnt change, it stays the old id
Then check if the user has edited the values and call press yourself before using the value.but in that case if the users passes the combo without pressing return key, the id doesnt change, it stays the old id
Bookmarks