Results 1 to 16 of 16

Thread: QComboBox BUG?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QComboBox BUG?

    You can use this simple code if you want to check it out
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QComboBox>
    3. #include <QStandardItemModel>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. model->appendRow(new QStandardItem(QString("item1")));
    10. model->appendRow(new QStandardItem(QString("item2")));
    11. model->appendRow(new QStandardItem(QString("item3")));
    12. model->appendRow(new QStandardItem(QString("item4")));
    13.  
    14.  
    15. QComboBox *combo = new QComboBox();
    16. combo->setModel(model);
    17. combo->setEditable(true);
    18. combo->setInsertPolicy(QComboBox::NoInsert);
    19. combo->setMinimumWidth(100);
    20.  
    21. combo->show();
    22.  
    23. return a.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    To reproduce:
    1.) Start this simple App and select item3 for example by moving down arrow key.
    2.) Select full text "item3" in the combo either by double click or with shift and arrow keys.
    3.) Press Enter.
    You will see that after pressing Enter combo box is moving to previous set index, which in this case will be "item1".


    Can I avoid this behaviour?

  2. #2
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox BUG?

    Does anybody have any solution? I really need this.
    I made my own system for tab ordering which responds to enter key. However, when user get into combo box and press enter value is changed, which is of course not appropriate behavior.
    For the information, I am setting focus on the combo or any other widget with setFocus(Qt::TabFocusReason) and get the text inside selected.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QComboBox BUG?

    How about not using a model? It doesn't make much sense to use a model with an editable combo anyway.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,679
    Thanks
    13
    Thanked 1,597 Times in 1,525 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QComboBox BUG?

    I don't see that behaviour in the example program here: Qt 4.7.4 on Linux.

  5. #5
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox BUG?

    @wysota: I use model cause I work with database tables(note: QSqlQueryModel which is not editable). I need editable combo only to use autocompleter from lineedit control inside the combo.

    @ChrisW67: Do you redo the steps exactly as I said? Because in some cases it does work properly indeed(but rarely). I am using Qt 4.8.0, but I tested on 4.7.4 on Linux with the same result.

    If you want I will put a small test project here with my tab order mechanism and combos, so you will easily reproduce.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QComboBox BUG?

    Quote Originally Posted by mak_user View Post
    I need editable combo only to use autocompleter from lineedit control inside the combo.
    Huh?!? please elaborate... You can always create a QCompleter with a model yourself.

  7. #7
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox BUG?

    I am already working on a project with lot of combos used like this. I would like to make it work this way by finding workaround over this strange behavior. This is small example of what is happening, attached in message.
    Now, just press enter or return key and you will see value of combo2 changed.
    You can change the value of any combo yourself by moving with up/down arrow key inside a combo and then continue clicking enter and you will see the same behavior.
    What is strange if you set a value in the combo by using autocompleter(type the text item3 for example) and press enter then this value is remembered and tab ordering works fine on this field.
    Do you understand my problem now?
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox BUG?

    Why nobody even view my example? Am I doing something wrong or it is a QComboBox bug?

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,679
    Thanks
    13
    Thanked 1,597 Times in 1,525 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QComboBox BUG?

    Quote Originally Posted by mak_user View Post
    @ChrisW67: Do you redo the steps exactly as I said? Because in some cases it does work properly indeed(but rarely). I am using Qt 4.8.0, but I tested on 4.7.4 on Linux with the same result.
    I copied your code example, compiled it, run it, pressed the down arrow twice to select item3, pressed Enter. Item3 remained selected, exactly as expected. I repeated it with the mouse to select item 3: same result. Since you are doing something custom with Enter key presses I would start by looking there.

    Quote Originally Posted by mak_user View Post
    Why nobody even view my example? Am I doing something wrong or it is a QComboBox bug?
    It could be that:
    • Not everyone is in your time zone: I certainly wasn't waiting at 00:45 this morning for your post.
    • Not everyone has unlimited time to debug other people's code.
    • Nobody cares


    A quick download and build of your code: no problem with either the value in the edited combo box or the change of focus.

    I am wondering why you maintain a separate list of widgets to determine where next to put focus. Surely QWidget::nextInFocusChain() is an obvious candidate for this given that you have a pointer to the widget with the key press event.

  10. The following user says thank you to ChrisW67 for this useful post:

    mak_user (31st January 2012)

  11. #10
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox BUG?

    How do I set this chain?
    I was using "void QWidget::setTabOrder ( QWidget * first, QWidget * second )" before this custom ordering, but there was a bug in it for sure when I have widget with child widget and set focusProxy on it. I can send you an example code of this too if you care .

    I am wondering however, how it is possible to work at your place and not at mine. I am using Qt4.7.4 on Linux to debug this.
    Do you saying that when you press enter on second combo where "item4" is selected it doesn't revert value to "item1"?
    This is strange. I have reproducible behavior here every time I start the application.
    What I am doing is start my app and press enter several times and got all three combos set to "item1".

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QComboBox BUG?

    Quote Originally Posted by mak_user View Post
    I am wondering however, how it is possible to work at your place and not at mine. I am using Qt4.7.4 on Linux to debug this.
    Do you saying that when you press enter on second combo where "item4" is selected it doesn't revert value to "item1"?
    This is strange. I have reproducible behavior here every time I start the application.
    What I am doing is start my app and press enter several times and got all three combos set to "item1".
    $ qmake -v | grep 4.
    Using Qt version 4.7.4 in /usr/lib/x86_64-linux-gnu

    If I just keep pressing Enter then I end up with all combos set to item1. If I choose an entry and press enter, it sticks properly. I wouldn't be suprised if this was caused by a non-editable model. And again, as I said earlier, I gave it a thought more than once and I claim that there is no sense in using a model with an editable combo unless you heavily customize the editing to avoid damaging the model.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    mak_user (31st January 2012)

  14. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,679
    Thanks
    13
    Thanked 1,597 Times in 1,525 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QComboBox BUG?

    Quote Originally Posted by mak_user View Post
    Do you saying that when you press enter on second combo where "item4" is selected it doesn't revert value to "item1"?
    No, I am saying that when I test it the way you asked it doesn't fail in the way you describe. You asked us to select a value on the combo then press enter. What you are doing is just pressing enter on the existing value.
    What I am doing is start my app and press enter several times and got all three combos set to "item1".
    Doing that does result in the second combo switching to item1.
    Removing your event filter does not change this.
    Allowing insertion does not change this.

    Once a value has been selected through the GUI the problem no longer exists. This looks like an initialisation issue inside the QComboBox code.

    If nobody else has a bright idea, search for a bug report in the Qt Bugtracker. If you don't find one then, using QTestLib, write an automated test that demonstrates the problem and lodge a bug report. Even better, find the actual fault.

    BTW, can I determine if QWidget* points to QComboBox?
    qobject_cast<>()

  15. The following user says thank you to ChrisW67 for this useful post:

    mak_user (31st January 2012)

Similar Threads

  1. Set value to QComboBox
    By Archa4 in forum Newbie
    Replies: 2
    Last Post: 19th May 2011, 13:46
  2. Qcombobox
    By Project25 in forum Qt Programming
    Replies: 2
    Last Post: 16th December 2009, 20:29
  3. QComboBox
    By kavinsiva in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2009, 17:11
  4. QComboBox
    By bismitapadhy in forum Qt Programming
    Replies: 7
    Last Post: 15th July 2009, 07:01
  5. QComboBox
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 31st August 2007, 14:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.