Results 1 to 9 of 9

Thread: QComboBox as a trigger

  1. #1
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QComboBox as a trigger

    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:
    Qt Code:
    1. interfaceComboBox = new QComboBox(configureConnectionBox);
    2. interfaceComboBox->setObjectName(QString::fromUtf8("interface"));
    3. interfaceComboBox->setStatusTip(QString::fromUtf8("Select your interface of choice here."));
    4. interfaceComboBox->setToolTip(QString::fromUtf8("Select your interface of choice here."));
    5. interfaceComboBox->setGeometry(QRect(12,25,100,20)); // my trigger
    6. connect(interfaceComboBox, SIGNAL(clicked()), this, SLOT(openInterfaceSelector()));
    To copy to clipboard, switch view to plain text mode 

    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]

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBox as a trigger

    I don't see such signal at all in QComboBox docs. One idea worth trying would be to reimplement virtual method QComboBox::showpopup().
    J-P Nurmi

  3. #3
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QComboBox as a trigger

    Hi again,

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

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

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBox as a trigger

    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.
    J-P Nurmi

  5. #5
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QComboBox as a trigger

    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
    Last edited by ape; 4th February 2008 at 08:06.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBox as a trigger

    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.
    Qt Code:
    1. void MyComboBox::showPopup()
    2. {
    3. if (!initialized)
    4. {
    5. initializeContents();
    6. }
    7. QComboBox::showPopup();
    8. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    ape (4th February 2008)

  8. #7
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QComboBox as a trigger

    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.

    Qt Code:
    1. void MainWindow::showPopup()
    2. {
    3. // re-Init-Section
    4. // ....
    5. // ....
    6. // end- re-Init Section
    7.  
    8. QComboBox::showPopup();
    9. }
    To copy to clipboard, switch view to plain text mode 

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

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QComboBox as a trigger

    Quote Originally Posted by ape View Post
    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.
    Qt Code:
    1. class MyComboBox : public QComboBox
    2. {
    3. ...
    4. };
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  10. The following user says thank you to jpn for this useful post:

    ape (4th February 2008)

  11. #9
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QComboBox as a trigger

    ok i guess i got it.

    Thanks again for your nice help jpn.

Similar Threads

  1. QComboBox
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 12th December 2007, 06:38
  2. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  3. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  4. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14
  5. QDataWidgetMapper <=> QComboBox best practice
    By saknopper in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 10:50

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.