Results 1 to 5 of 5

Thread: [QComboBox] (pre-)select no item. (solved)

  1. #1
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question [QComboBox] (pre-)select no item. (solved)

    Hi,
    Has anyone a link to what is the policy in QComboBox for setting
    the preselection (the current selected item at showing time) ?
    As I have two comboboxes that I fill in the same way
    Qt Code:
    1. cbb->addItem("String", myInt)
    To copy to clipboard, switch view to plain text mode 
    , and I don't use setCurrentIndex.
    I get the first combo pre-selecting the first item and
    the second combo pre-selecting none.
    What triggers the pre-selection ?
    Thanks in advance.

    Edit: it appears that, in fact, the second combo has its first line selected,
    but as it is an empty line I thought it was not (selected).
    So my question becomes (as I tried setCurrentIdx(-1)) :
    how do I make a not editable combobox select no item ?
    Last edited by lauranger; 17th July 2006 at 13:42.

  2. #2
    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] default (pre-)selected item

    Always the first item is selected unless you change the selection using setCurrentIndex. For comboboxes where you can enter your own items (I think they are called "editable") none of the items are selected by default.

  3. #3
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [QComboBox] default (pre-)selected item

    Hi Wysota
    As stated in my first post :
    I don't use setCurrentIndex.
    I get the first combo pre-selecting the first item and
    the second combo pre-selecting none.
    And after adding setCurrentIndex(-1) to the first combo,
    I still have the first item selected in it.
    I guess it is something related to the default button in
    a dialog (I show those combo in a wizard dialog).
    What could I do, cheaper than subclassing ?

  4. #4
    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] default (pre-)selected item

    Add an empty item at the beginning. Regular comboboxes don't allow a state where "no item" is selected. The selection has to be valid all the time.

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

    lauranger (17th July 2006)

  6. #5
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [QComboBox] (pre-)select no item

    OK that makes sense to me. thanks.
    Last edited by lauranger; 17th July 2006 at 13:31.

Similar Threads

  1. Replies: 5
    Last Post: 27th May 2006, 13:44
  2. QListWidget/QTreeWidget, etc selected item color
    By Arthur in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2006, 16:50
  3. QListWidgetItem check/uncheck
    By Arthur in forum Qt Programming
    Replies: 6
    Last Post: 12th May 2006, 10:19
  4. Programattically Clicking an Item in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 4
    Last Post: 11th May 2006, 16:26
  5. Replies: 1
    Last Post: 23rd March 2006, 06:37

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.