Results 1 to 5 of 5

Thread: QComboBox

  1. #1
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QComboBox

    Can I have a QComboBox with a validator with invalid input and still have it editable?

    To answer my own question; No.

    So my question is there an easy workaround for this before I dig deeper into a solution.

    I need to have a editable QComboBox with numeric input entries with attached explanation test.

    Qt Code:
    1. QComboBox *cBox = new QComboBox(this);
    2.  
    3. cBox->setEditable(true);
    4. QRegExp ireg("([0-9]{10})");
    5. QRegExpValidator *iValidator = new QRegExpValidator(ireg,this);
    6. cBoxt->setValidator(iValidator);
    7.  
    8. cBox->addItem(tr("1 - this an explanation"));
    9. cBox->addItem(tr("2 - this also an explanation"));
    To copy to clipboard, switch view to plain text mode 

    The above will not function correctly due to the validator but I must maintain the ability to let the user enter a number that might not be present in the combobox.

    Any suggestions?

    Bob

  2. #2
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBox

    You may write custom validator, note that validators have 3 states - invalid, INTERMEDIATE and acceptable.
    You can also think about completer, it can be usefull too.

    As for me attached explanation text obviously means tooltips instead of regular texts.
    Or texts in combo's list, but cut of from lineEdit when selecting an item(as fit to window in zoom combobox).
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

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

    Default Re: QComboBox

    Quote Originally Posted by coderbob View Post
    Can I have a QComboBox with a validator with invalid input and still have it editable?
    Why not?

    The above will not function correctly due to the validator but I must maintain the ability to let the user enter a number that might not be present in the combobox.

    Any suggestions?
    1. Don't use combobox, but a completer as suggested

    or

    2. Write a custom delegate for your combobox's listview where you will display not only the main data but also the explanation text. The item's "text" will still only be a number, but something else will be displayed.

  4. #4
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QComboBox

    Thank you for the suggestions.

    Wysota,

    Quote:
    Originally Posted by coderbob View Post
    Can I have a QComboBox with a validator with invalid input and still have it editable?

    Originally Posted by Wysota
    Why not?
    I do not recall the exact source but the Trolls say some where that it is a bad idea and in the code I attempted it causes random results.

    I was using a completer along with the combo box but to use just a completer still leaves me with the problem of invalid input due to explanation text next to the selections. I Would use tooltips but that takes an extra step to view, might not always be apparent to end users, and over all just makes things more complicated for the end user.

    A custom delegate might be the best way to go on this.

    Thanks again for the help

    Bob

    EDIT:
    I thought (hoped) that invalid input from a combo box would just be dropped and it would leave me with the data I needed but still provide the extra information.

  5. #5
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBox

    hmm, so way not connecting current item changed and cut explanation texts visible in combo's list to keep lineEdit numerical only.
    You would have explanations visible while selecting items from list, but validator would accept only numbers.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

Similar Threads

  1. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. Style Sheet color of QComboBox
    By tpf80 in forum Qt Programming
    Replies: 6
    Last Post: 25th June 2007, 02:55
  4. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14
  5. QDataWidgetMapper <=> QComboBox best practice
    By saknopper in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 10:50

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.