Results 1 to 5 of 5

Thread: avoid duplicates items in comboBox

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default avoid duplicates items in comboBox

    Hi, I'm trying to avoid insert duplicates in a combox; insert item is called many times..
    But don't works; every times isertItem() is called, it adds the same item in the comboBox.Why?
    Qt Code:
    1. comboBox->setDuplicatesEnabled(FALSE); //this is in mainForm constructor
    2. void MainForm::insertItem() {
    3. (checkboxi[1]->isChecked()) ? comboBox->insertItem("item2",2) :
    4. comboBox->removeItem(2);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: avoid duplicates items in comboBox

    Quote Originally Posted by mickey
    Why?
    Because you haven't read the documentation:
    bool duplicatesEnabled
    This property holds whether duplicates are allowed.
    If the combobox is editable and the user enters some text in the combobox's lineedit and presses Enter (and the insertionPolicy() is not NoInsertion), then what happens is this:
    If the text is not already in the list, the text is inserted.
    If the text is in the list and this property is TRUE (the default), the text is inserted.
    If the text is in the list and this property is FALSE, the text is not inserted; instead the item which has matching text becomes the current item.
    This property only affects user-interaction. You can use insertItem() to insert duplicates if you wish regardless of this setting.
    Set this property's value with setDuplicatesEnabled() and get this property's value with duplicatesEnabled().

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: avoid duplicates items in comboBox

    OK. Then: I need insert and remove element in comboBox; to do this avoiding dupicate, do I implement the mechanism? Oe is there an istruction? (I don't find it) .Thanks
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: avoid duplicates items in comboBox

    You will have to implement this yourself.

  5. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: avoid duplicates items in comboBox

    Or simply check that the item isn't there before inserting it.

Similar Threads

  1. Combobox with checkable items
    By qtneuling in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2008, 14:42
  2. Sorting Combobox Items
    By raphaelf in forum Newbie
    Replies: 5
    Last Post: 23rd June 2008, 08:00
  3. Creating events for combobox items
    By confused in forum Newbie
    Replies: 4
    Last Post: 26th March 2006, 16:40

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
  •  
Qt is a trademark of The Qt Company.