Results 1 to 3 of 3

Thread: QComboBox minor problem

  1. #1
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QComboBox minor problem

    This is a problem for Qt 4.6.0. For 4.5.3 I think it did not exist.

    I have a minor problem with QComboBox: I insert items, and make current index -1, so that no item is selected. But when I press the down arrow and go with the mouse over the first entry, it is not highlighted. Only if I go to the second entry and then back to the first entry, the first entry is highlighted.

    I attach a small code:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QDialog dialog;
    8.  
    9. dialog.resize(300,200);
    10.  
    11. QComboBox* combo=new QComboBox(&dialog);
    12.  
    13. combo->addItem("first");
    14. combo->addItem("second");
    15. combo->addItem("third");
    16. combo->addItem("fourth");
    17.  
    18. combo->setCurrentIndex(-1);
    19.  
    20. dialog.show();
    21.  
    22. return app.exec();
    23.  
    24. return 0;
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by lalesculiviu; 11th December 2009 at 18:47.

  2. #2
    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 minor problem

    Works fine here.

  3. #3
    Join Date
    Oct 2009
    Location
    Craiova, Romania
    Posts
    46
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox minor problem

    I attach a new file (k2.cpp, see also listing). It demonstrates a problem: when you press the combo, it writes the current index of the view() of the combo box. It is the first entry for the first time (which is incorrect, because the current index is -1). If you move the mouse to the second line, then close the popup, and click to open popup again, the current index is now correctly -1.

    Qt Code:
    1. #include <QtGui>
    2. #include <QModelIndex>
    3.  
    4. #include <iostream>
    5. using namespace std;
    6.  
    7. class ComboBox:public QComboBox{
    8. public:
    9. ComboBox(QWidget* parent):QComboBox(parent){}
    10.  
    11. void addItem(const char* s){QComboBox::addItem(s);}
    12.  
    13. void setCurrentIndex(int i){QComboBox::setCurrentIndex(i);}
    14.  
    15. void showPopup(){
    16. QComboBox::showPopup();
    17.  
    18. QModelIndex mi=view()->currentIndex();
    19. cout<<"mi.isValid()=="<<mi.isValid()<<", mi.row()=="<<mi.row()<<", mi.column()=="<<mi.column()<<endl;
    20. }
    21. };
    22.  
    23. int main(int argc, char* argv[])
    24. {
    25. QApplication app(argc, argv);
    26.  
    27. QDialog dialog;
    28.  
    29. dialog.resize(300,200);
    30.  
    31. ComboBox* combo=new ComboBox(&dialog);
    32.  
    33. combo->addItem("first");
    34. combo->addItem("second");
    35. combo->addItem("third");
    36. combo->addItem("fourth");
    37.  
    38. combo->setCurrentIndex(-1);
    39.  
    40. dialog.show();
    41.  
    42. return app.exec();
    43.  
    44. return 0;
    45. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

Similar Threads

  1. QItemDelegate, QDataWidgetMapper and QComboBox
    By cydside in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2009, 19:44
  2. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 20:25
  3. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2007, 00:29
  4. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 17:14
  5. QDataWidgetMapper <=> QComboBox best practice
    By saknopper in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 11:50

Tags for this Thread

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.