PDA

View Full Version : QomboBox - activated(), highlighted()



Salazaar
6th June 2007, 13:55
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?

high_flyer
6th June 2007, 14:05
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.

Salazaar
6th June 2007, 15:38
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...


void Dialog::whichDialog()
{
if(itemName->activated())
...
}

Would it be correct? And if no, how should it be?
edit:
and what will be the item name, If designer generated this:

comboBox->addItem(QApplication::translate("Dialog", "Beaufort", 0, QApplication::UnicodeUTF8));

BrainB0ne
6th June 2007, 15:50
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.. :)

Salazaar
6th June 2007, 16:09
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;))

Salazaar
6th June 2007, 19:42
Does anyone know?

high_flyer
11th June 2007, 09:16
use QComboBox::activated()

Salazaar
11th June 2007, 17:57
But it is important which 'line' was chosen

high_flyer
11th June 2007, 18:03
Wnat do you mean?
Could you explain more what the problem is?

BrainB0ne
14th June 2007, 10:35
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:


if(yourComboBox->currentText() == "YourTextAtItemNumber1")
{
// open your dialog.....
}


or



if(yourComboBox->currentItem() == 1)
{
// open your dialog.....
}

Salazaar
14th June 2007, 11:50
Thanks that's the answer I was looking for