Results 1 to 5 of 5

Thread: QComboBox and item

  1. #1
    Join Date
    Feb 2006
    Location
    Roma ( Italy )
    Posts
    7
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Unhappy QComboBox and item

    Hi,
    I have a question:
    I have 3 item in a combo: red, green, blue.
    I want to remove "blue" but I don't have any index

    Hou can I remove a item in QComboBox withuot use index?

    bye!

  2. #2
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox and item

    I don't know the specifics of your situation, but I guess you could clear the combobox, and then re-insert all the items except the "blue" one. But this isn't as nice as if you had the index.

    Bojan
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

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

    drow (14th June 2006)

  4. #3
    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 and item

    Quote Originally Posted by drow
    I have 3 item in a combo: red, green, blue.
    Do you mean items named "red", "green" and "blue"?

    Why don't you just search for it?
    Qt Code:
    1. // iterate through the items and find the one to be removed
    2. for (int = 0; i < combo->count(); ++i) {
    3. if (combo->text(i) == "blue") {
    4. combo->removeItem(i);
    5. break;
    6. }
    7. }
    8.  
    9. // OR make use of QComboBox::setCurrentText()
    10. combo->setCurrentText("blue");
    11. combo->removeItem(combo->currentItem());
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    drow (14th June 2006)

  6. #4
    Join Date
    Feb 2006
    Location
    Roma ( Italy )
    Posts
    7
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Thumbs up Re: QComboBox and item

    Quote Originally Posted by Bojan
    I don't know the specifics of your situation, but I guess you could clear the combobox, and then re-insert all the items except the "blue" one. But this isn't as nice as if you had the index.

    Bojan
    I mast remove more item ( 100 - 800 item ) and this solution isn't efficent

    Quote Originally Posted by jpn
    // OR make use of QComboBox::setCurrentText()
    combo->setCurrentText("blue");
    combo->removeItem(combo->currentItem());
    I'll try this solution

    thk's all

    drow

  7. #5
    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 and item

    If you have this many items, it'll be best if you store indices of all items, for example in a QHash or something like that (but you have to use the model approach with persistant indices for that).

  8. The following user says thank you to wysota for this useful post:

    drow (15th June 2006)

Similar Threads

  1. Automatically add items to a QComboBox (Qt4)
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2006, 15:32
  2. no MouseButtonRelease event for QComboBox
    By Beluvius in forum Qt Programming
    Replies: 5
    Last Post: 31st March 2006, 12:58
  3. QcomboBox items
    By therealjag in forum Newbie
    Replies: 5
    Last Post: 27th March 2006, 08:21

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.