Results 1 to 11 of 11

Thread: QomboBox - activated(), highlighted()

  1. #1
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QomboBox - activated(), highlighted()

    Hi. I've got a question. I read documentation of QComboBox but I don't know what's the difference between activated() and highlighted(). I want to do something like this: If number 1 is selected in comboBox, and user clicks ok button, than another window is displayed. Which of there 2 functions should I use?

  2. #2
    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: QomboBox - activated(), highlighted()

    There are two signals emitted if the current item of a combobox changes, currentIndexChanged() and activated(). currentIndexChanged() is always emitted regardless if the change was done programmatically or by user interaction, while activated() is only emitted when the change is caused by user interaction. The highlighted() signal is emitted when the user highlights an item in the combobox popup list.
    In other words:
    activated() is sent when you make a new selection.

    You might have a selection in the combox, but focus on other widget.
    When the focus returns to the combox, the current selected item will be highlighted, and the highlighted signal is sent - in this case, no selection change is made.
    Use the one you thik is apropriate.
    ==========================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.

  3. #3
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QomboBox - activated(), highlighted()

    And if I want to do something like this: When user clicks a button, function is called. And in this function, I want to do if combo item was activated, than...
    Qt Code:
    1. void Dialog::whichDialog()
    2. {
    3. if(itemName->activated())
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 

    Would it be correct? And if no, how should it be?
    edit:
    and what will be the item name, If designer generated this:
    Qt Code:
    1. comboBox->addItem(QApplication::translate("Dialog", "Beaufort", 0, QApplication::UnicodeUTF8));
    To copy to clipboard, switch view to plain text mode 
    Last edited by Salazaar; 6th June 2007 at 16:43.

  4. #4
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QomboBox - activated(), highlighted()

    I think u can best use the clicked() signal from the OK button and connect that signal to a slot you have created.... when arriving in that slot, ask the text that is present at your combobox and check it against your "number 1".

    Thats my opinion how i should do it..
    ..:: Still Standing Strong ::..

  5. #5
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QomboBox - activated(), highlighted()

    Quote Originally Posted by BrainB0ne View Post
    I think u can best use the clicked() signal from the OK button and connect that signal to a slot you have created
    That's what I've done And about this slot, how can I compare text with "number one"? As you've seen in the code that Designer generated, there's no thing such as number1 or item1, so how would the comparision look like? (in code, as well)

  6. #6
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QomboBox - activated(), highlighted()

    Does anyone know?

  7. #7
    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: QomboBox - activated(), highlighted()

    use QComboBox::activated()
    ==========================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.

  8. #8
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QomboBox - activated(), highlighted()

    But it is important which 'line' was chosen

  9. #9
    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: QomboBox - activated(), highlighted()

    Wnat do you mean?
    Could you explain more what the problem is?
    ==========================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.

  10. #10
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QomboBox - activated(), highlighted()

    Quote Originally Posted by Salazaar View Post
    That's what I've done And about this slot, how can I compare text with "number one"? As you've seen in the code that Designer generated, there's no thing such as number1 or item1, so how would the comparision look like? (in code, as well)
    well, we have two functions here:

    int QComboBox::currentItem () const
    Returns the index of the current item in the combobox. See the "currentItem" property for details.

    QString QComboBox::currentText () const
    Returns the text of the combobox's current item. See the "currentText" property for details.

    I assume you know the contents of the combobox, you can use an if statement like:
    Qt Code:
    1. if(yourComboBox->currentText() == "YourTextAtItemNumber1")
    2. {
    3. // open your dialog.....
    4. }
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. if(yourComboBox->currentItem() == 1)
    2. {
    3. // open your dialog.....
    4. }
    To copy to clipboard, switch view to plain text mode 
    ..:: Still Standing Strong ::..

  11. #11
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QomboBox - activated(), highlighted()

    Thanks that's the answer I was looking for

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.