Results 1 to 3 of 3

Thread: QPushButton resize event

  1. #1
    Join Date
    May 2010
    Location
    Holguín City, Cuba
    Posts
    13
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default QPushButton resize event

    How I can know when a button has been resized?

    Thanks.

  2. #2
    Join Date
    Oct 2010
    Posts
    55
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    9

    Default Re: QPushButton resize event

    You could use an event filter, if you have a MainWindow class for example:

    Qt Code:
    1.  
    2. class MainWindow : public QMainWindow
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. MainWindow(QWidget *parent = 0);
    8. ~MainWindow();
    9.  
    10. bool eventFilter(QObject *object, QEvent *event);
    11.  
    12. private:
    13. QPushButton* _button;
    14. };
    To copy to clipboard, switch view to plain text mode 

    In the constructor, I put:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent),
    3. _button(new QPushButton)
    4. {
    5. setCentralWidget(_button);
    6. _button->installEventFilter(this);
    7. }
    To copy to clipboard, switch view to plain text mode 

    This way, MainWindow will receive all events sent to the button. The definition for eventFilter() could look like:

    Qt Code:
    1. bool MainWindow::eventFilter(QObject *object, QEvent *event)
    2. {
    3. if (_button == object && event->type() == QEvent::Resize) {
    4. qDebug() << "button was resized!";
    5. }
    6.  
    7. return QMainWindow::eventFilter(object, event);
    8. }
    To copy to clipboard, switch view to plain text mode 

    You could also extend QPushButton and emit a signal when a resize event occurs. It all depends on your particular use-case.
    Last edited by helloworld; 5th February 2011 at 03:50.

  3. The following user says thank you to helloworld for this useful post:

    gcubar (7th February 2011)

  4. #3
    Join Date
    May 2010
    Location
    Holguín City, Cuba
    Posts
    13
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton resize event

    Thanks, this is what I needed.

Similar Threads

  1. How to get screen resize event?
    By kamlesh.sangani in forum Qt Programming
    Replies: 8
    Last Post: 10th March 2010, 08:46
  2. How to resize the QIcon inside QPushButton dynamically?
    By gboelter in forum Qt Programming
    Replies: 2
    Last Post: 18th February 2010, 12:34
  3. resize event
    By wirasto in forum Qt Programming
    Replies: 6
    Last Post: 16th July 2009, 10:01
  4. Resize event
    By boss_bhat in forum Qt Programming
    Replies: 5
    Last Post: 19th July 2006, 15:43
  5. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32

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.