Results 1 to 4 of 4

Thread: [QComboBox] setEditable resets validator and completer

  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default [QComboBox] setEditable resets validator and completer

    I've noticed every time editable state of QComboBox is changed, its validator and completer are set to 0. The same strange thing happens with the stylesheet: if you apply some custom style to editable combobox it won't work when you change editable state. I'd like to know if this weird behavior was intended or just something unnoticed by developers.

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [QComboBox] setEditable resets validator and completer

    Styles seem to work fine for me.

    Completer is removed because when you set editable to false the edit line is deleted (and completer with it).
    The same happens for validator as both are children of a line edit which gets deleted when you set editable to false.

  3. #3
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: [QComboBox] setEditable resets validator and completer

    Completer is removed because when you set editable to false the edit line is deleted (and completer with it).
    The same happens for validator as both are children of a line edit which gets deleted when you set editable to false.
    Yes, I know why it happens, but I don't think it's a normal behavior, so just wanted to point it out, because it looks like a bug.

    Stylesheet doesn't work correctly. Here goes a small sample that illustrates the issue. As you can see the background of the combobox should be blue, but it turns white (or default window color on your system) after making it editable. The issue is also caused by line edit deletion and when a new edit is created stylesheet is not applied. If I manually apply stylesheet again it works fine (see the commented line in the code).

    Qt Code:
    1. #include <QApplication>
    2. #include <QComboBox>
    3.  
    4. class MyComboBox: public QComboBox
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. MyComboBox(): QComboBox()
    10. {
    11. setStyleSheet("QComboBox { background-color: blue; }");
    12. addItem("item 1");
    13. addItem("item 2");
    14. connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleNewIndex(int)));
    15. }
    16.  
    17. private slots:
    18. void handleNewIndex(int index)
    19. {
    20. setEditable(index % 2);
    21. // after changing editable state we have to reapply stylesheet
    22. //style()->polish(this);
    23. }
    24. };
    25.  
    26. int main(int argc, char *argv[])
    27. {
    28. QApplication a(argc, argv);
    29. MyComboBox cbox;
    30. cbox.show();
    31. return a.exec();
    32. }
    33.  
    34. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [QComboBox] setEditable resets validator and completer

    You're right.
    I've used border which works fine, but the background in fact is gone with the line edit.

    I agree that it seem like some overlooked bug.

    In fact there is an issue about stylesheets but I can't find anything about completer or validator.
    It may be worth rising it.

Similar Threads

  1. N97 mini resets when running deployed version QSolitaire 1.2.
    By skeletor in forum Installation and Deployment
    Replies: 1
    Last Post: 8th September 2010, 20:19
  2. Replies: 0
    Last Post: 19th April 2010, 16:29
  3. Replies: 13
    Last Post: 21st May 2009, 07:43
  4. completer and QComboBox
    By olosie in forum Qt Programming
    Replies: 8
    Last Post: 17th May 2009, 10:34
  5. Completer on QItemDelegate
    By gemidjy in forum Qt Programming
    Replies: 6
    Last Post: 31st March 2008, 10:29

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.