Results 1 to 3 of 3

Thread: Set Default text in QCombo box

  1. #1
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Set Default text in QCombo box

    Hi,
    I want to create a combo box so that it has some default text and whenever an item is selected form dropdown menu the item gets appended to default text.
    something like this

    |------------------|--|
    |SEX: MALE |V |
    !________________!__|
    MALE
    FEMALE

    so when i click FEMALE it should look like

    |------------------|--|
    |SEX: FEMALE |V |
    !________________!__|
    MALE
    FEMALE

  2. #2
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Set Default text in QCombo box

    I guess there is no simple way to do that. Unlike QSpinBox and QDoubleSpinBox, QComboBox doesn't have a method such setPrefix or setSuffix.
    In model-view convenience, it is possible to customize the data. In this case, what you have to do is creating the model, modifying the data and specify how it displayed through the model.
    ~ We are nothing in this universe ~

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Set Default text in QCombo box

    Just create a slot which you connect to one of the signals that signal itme selection, and in that slot change the contents of the first element in such that it will include the text of the current selected item.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Need help on setting up Defult text on QCombo box
    By Askar in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2011, 10:50
  2. Combo box is not showing any text by default
    By chandan in forum Qt Programming
    Replies: 0
    Last Post: 1st February 2011, 10:43
  3. QLineEdit default text
    By Guilo in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2011, 10:44
  4. Replies: 0
    Last Post: 9th May 2010, 14:14
  5. Qcombo box
    By nErnie in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2006, 00:56

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.