Results 1 to 4 of 4

Thread: QcomboBox autoCompletion

  1. #1
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QcomboBox autoCompletion

    Hi all,
    hoping this won't be a trivial question, I'd like to know if it's possible to prevent the user from entering invalid data when filling a QComboBox editable with autoCompletion.
    I mean, I have a list of Countries and to help the user I set the combo editable, but I don't want that user could write and leave invalid data (such as Germanysd...)
    I can check after but I'd like to avoid any invalid data to appear.
    thanks in advance

    bye

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QcomboBox autoCompletion

    Write a validator and set it with QComboBox::setValidator().
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    Lele (11th July 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    122
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QcomboBox autoCompletion

    thanks for replying,
    I can't figure it out how to write the QValidator::validate to accomplich my requirements,
    maybe I could check when user lost focus from the combo and put the closest string from the possible items.
    thanks again

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QcomboBox autoCompletion

    Don't give up. It's not so complicated!

    QComboBox uses a QStringListModel. Pass a QStringList fetched from the model to the validator to validate against. Here's a pseudo algo suggestion for QValidator::validate()
    Qt Code:
    1. if stringlist contains input
    2. return Acceptable
    3. else if input is empty or any string in the stringlist starts with input
    4. return Intermediate
    5. else
    6. return Invalid
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. The following 2 users say thank you to jpn for this useful post:

    frankiefrank (11th October 2012), Lele (12th July 2006)

Similar Threads

  1. QComboBox and item
    By drow in forum Qt Programming
    Replies: 4
    Last Post: 14th June 2006, 09:04
  2. Automatically add items to a QComboBox (Qt4)
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2006, 15:32
  3. QcomboBox items
    By therealjag in forum Newbie
    Replies: 5
    Last Post: 27th March 2006, 08:21
  4. QComboBox +SUSE10.0 +qt4.1 strange behavior
    By antonio.r.tome in forum Qt Programming
    Replies: 6
    Last Post: 20th March 2006, 17:49
  5. QComboBox inside QTableWidget
    By campana in forum Qt Programming
    Replies: 7
    Last Post: 20th March 2006, 17:22

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.