PDA

View Full Version : QComboBox as a trigger



ape
30th January 2008, 15:31
Hi,

i do have a QcomboBox which contains a list of interfaces available on the System (Windows).

Now i think it would make sense to add a selected trigger....means: if a user selects / opens the QComboBox i want to re-scan for existing interfaces.

I have tried it like that:


interfaceComboBox = new QComboBox(configureConnectionBox);
interfaceComboBox->setObjectName(QString::fromUtf8("interface"));
interfaceComboBox->setStatusTip(QString::fromUtf8("Select your interface of choice here."));
interfaceComboBox->setToolTip(QString::fromUtf8("Select your interface of choice here."));
interfaceComboBox->setGeometry(QRect(12,25,100,20)); // my trigger
connect(interfaceComboBox, SIGNAL(clicked()), this, SLOT(openInterfaceSelector()));


at the moment it looks like it happens just NOTHING if i select / open the QComboBox.

Am i using the wrong trigger ?


Best regards
ape


[/code]

jpn
30th January 2008, 19:50
I don't see such signal at all in QComboBox docs. One idea worth trying would be to reimplement virtual method QComboBox::showpopup().

ape
1st February 2008, 13:08
Hi again,

what do you think about using events for this special issue ?

http://doc.trolltech.com/4.3/eventsandfilters.html

jpn
1st February 2008, 15:27
I don't think it's a good idea. There are lots of (perhaps even style dependent) ways to make the combo box show its popup. But which ever way to user causes the combo box to show its popup, the virtual method QComboBox::showpopup() is always called. Just reimplement it and you'll get notified whenever the popup is shown. In your reimplementation you naturally call the base class implementation to actually do the job.

ape
4th February 2008, 07:55
Hi jpn,

thanks for your reply.

Could you try to explain me your idea a bit more detailed ?
At the moment i dont understand your idea 100%

QComboBox::showPopup:
>>Displays the list of items in the combobox. If the list is empty then the no items will be shown.

So how can i use showPopup to check if someone has clicked the box ?

Till now i just see the option to let the comboBox open itself with that function.....which must be triggered again by something else.


My target is too:
Run a specific function (re-scan for new interfaces) if a user opens my QcomboBox (which displays the available interfaces).


Best regards
ape

jpn
4th February 2008, 08:06
QComboBox::showPopup() gets called whenever the popup view is about to be shown. So what you could do is to reimplement it, initialize contents if appropriate and call the base class implementation to actually show the popup.


void MyComboBox::showPopup()
{
if (!initialized)
{
initializeContents();
}
QComboBox::showPopup();
}

ape
4th February 2008, 08:38
Ok i guess i do understand the basic idea now a bit better.

My first test does not work, but i guess that has something to do with my implementation.



void MainWindow::showPopup()
{
// re-Init-Section
// ....
// ....
// end- re-Init Section

QComboBox::showPopup();
}


Error:
mainwindow.cpp:350: error: cannot call member function `virtual void QComboBox::showPopup()' without object

jpn
4th February 2008, 08:42
Error:
mainwindow.cpp:350: error: cannot call member function `virtual void QComboBox::showPopup()' without object
You must subclass QComboBox. You cannot implement its method to another class eg. MainWindow.


class MyComboBox : public QComboBox
{
...
};

ape
4th February 2008, 08:57
ok i guess i got it.

Thanks again for your nice help jpn.