Results 1 to 13 of 13

Thread: Grid of QComboBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    483
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 97 Times in 94 Posts

    Default Re: Grid of QComboBox

    Here we go for the second approach (subclass QComboBox). I recommend the first approach (QSignalMapper), though.

    Disclaimer: I did not even try to compile this code, there may be errors.

    Qt Code:
    1. class MyComboBox : public QComboBox {
    2. Q_OBJECT
    3. public:
    4. MyComboBox(int id, QWidget *parent = 0);
    5. signals:
    6. void currentIndexChanged(int index, int id);
    7. protected slots:
    8. void onCurrentIndexChanged(int index);
    9. protected:
    10. int m_id;
    11. };
    12.  
    13. MyComboBox::MyComboBox(int id, QWidget *parent) : QComboBox(parent), m_id(id) {
    14. connect(this, SIGNAL(currentIndexChanged(int)), SLOT(onCurrentIndexChanged(int)));
    15. }
    16.  
    17. void MyComboBox::onCurrentIndexChanged(int index) {
    18. emit currentIndexChanged(index, m_id);
    19. }
    To copy to clipboard, switch view to plain text mode 
    Signals are not simple methods (although they are implemented by moc as methods). They are emitted by a component and you need to connect them to a slot to react to their emission.

  2. #2
    Join Date
    Nov 2009
    Posts
    61
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    9
    Thanked 3 Times in 3 Posts

    Default Re: Grid of QComboBox

    Thanks for this. I can see that your connect function has only three arguments whereas it should have 4: Widget, SIGNAL, Widget, SLOT ? Should there be this in the middle, as the third parameter?

  3. #3
    Join Date
    Oct 2009
    Posts
    483
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 97 Times in 94 Posts

    Default Re: Grid of QComboBox

    That is because I used the QObject::connect() non-static method, which is indeed equivalent to using the static one with "this" between the signal and the slot parameters.

Similar Threads

  1. Better Grid
    By Buby in forum Newbie
    Replies: 2
    Last Post: 7th September 2010, 09:18
  2. Grid-like Toolbar
    By dv_ in forum Qt Programming
    Replies: 1
    Last Post: 17th February 2009, 10:37
  3. drawing a grid
    By dreamer in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2008, 09:17
  4. Grid Problem
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2007, 10:40
  5. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 01:37

Tags for this Thread

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.