Results 1 to 4 of 4

Thread: QComboBox Selection Validator?

  1. #1
    Join Date
    Jan 2014
    Posts
    13
    Thanks
    3

    Default QComboBox Selection Validator?

    I have a QComboxBox presenting a list of choices and I'm connected to the currentIndexChanged signal.

    My situation is that when the user makes a selection I respond to the signal by presenting an 'Are you sure?' messages box. If the user selects 'no' I would like to set the combobox back to the last selection - basically cancelling the currentIndexChanged action.

    I've looked through the docs and I could only find a validator for the text being entered, not the choice itself. How can I do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Selection Validator?

    Not sure is this is what you are looking for, but the combo box has a QLineEdit child and it can have a QValidator set to validate its input.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2014
    Posts
    13
    Thanks
    3

    Default Re: QComboBox Selection Validator?

    I'm not talking about validating the text that a user may enter. My combobox has the editable property set to false and the user selecting a new entry in the combox box via the dropdown menu.

    For example, if I have a combobox with three entries [a,b,c] and the current selection is [a]. When the user selects [c], I would like to ask the user "Did you really mean to select [c]?" with a message dialog. If the user says "Yes" the we continue on - but if the user selects no then the selection of the combo box reverts back to the previously selected item.

    I've attached a validator but it's validate function is not being called for this action.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox Selection Validator?

    Ah, sorry, misread your original post.

    The class that handles the signal and shows the message box will have to remember the last valid index and call setCurrentIndex() if the user rejects the change.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    chouqud (20th February 2014)

Similar Threads

  1. QComboBox with multipe selection via tree
    By corwinj in forum Qt-based Software
    Replies: 2
    Last Post: 20th February 2015, 17:41
  2. Replies: 2
    Last Post: 26th September 2012, 09:26
  3. [QComboBox] setEditable resets validator and completer
    By mentalmushroom in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2012, 12:42
  4. QComboBox multi-column popup selection quirks [SOLVED]
    By ChrisW67 in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2011, 03:56
  5. prevent selection in QComboBox.
    By hicpalm in forum Qt Programming
    Replies: 6
    Last Post: 21st May 2008, 16:06

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.