Results 1 to 9 of 9

Thread: MainWindow Button

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: MainWindow Button

    If you want the button clicked on enter when it has the focus, you can just call setAutoDefault with true. If you want it clicked when pressing enter while it doesn't have the focus, you will have to intercept events for the QMainWindow rather than the button. You can do this by overriding the event function for QMainWindow.
    Qt Code:
    1. bool MainWindow::event(QEvent *event)
    2. {
    3. if (event->type() == QEvent::KeyPress)
    4. {
    5. QKeyEvent *ke = static_cast<QKeyEvent *>(event);
    6. if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return)
    7. {
    8. qDebug() << "click";
    9. ui->pbSave->click();
    10. return true;
    11. }
    12. }
    13. return QMainWindow::event(event);
    14. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to numbat for this useful post:

    waynew (27th December 2009)

Similar Threads

  1. button background color when it is clicked
    By navi1084 in forum Qt Programming
    Replies: 5
    Last Post: 24th June 2024, 12:09
  2. Replies: 5
    Last Post: 1st March 2010, 15:55
  3. button with backgr and icon using stylesheets
    By s_p_t10 in forum Qt Programming
    Replies: 0
    Last Post: 7th May 2008, 20:19
  4. Button on the Upper Right Corner of MainWindow?
    By vishal.chauhan in forum Qt Programming
    Replies: 10
    Last Post: 12th March 2008, 10:47
  5. Replies: 1
    Last Post: 11th September 2007, 13:34

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.