Results 1 to 5 of 5

Thread: Adding click event to QFrame

  1. #1
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Adding click event to QFrame

    Can someone, please point me to a tutorial or explain how exactly to add a mousebuttonpress event to a QFrame so I can connect it to a slot?

  2. #2
    Join Date
    Apr 2010
    Posts
    37
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding click event to QFrame

    Basically, what I'm trying to do is use use a QFrame as a QPushButton

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding click event to QFrame

    Why dont you simply set QPushButton to flat ?
    see QPushButton::setFlat

  4. #4
    Join Date
    Jul 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding click event to QFrame

    Reason not to use QPushButton::flat ist that QPushButton is atomic widget, not everything goes inside of it, and QFrame is just a frame, so basically surrounding the all widgets inside of it.

    Just reimplement mousePressedEvent(QMouseEvent *me), mouseReleseEvent(QMouseEvent *me), and do like:

    Qt Code:
    1. void mousePressedEvent(QMouseEvent *me) {
    2. if (me->buttons() ^ me->button()) {QFrame::mousePressedEvent(me); return;}
    3.  
    4. if (me->button() == QMouseEvent::LeftMouse) {
    5. emit(myMousePressedSignal());
    6. // here you shoud remember click event...
    7. me->accept();
    8. return;
    9. }
    10.  
    11. QFrame::mousePressedEvent(me);
    12. }
    13.  
    14. void mouseRelessedEvent(QMouseEvent *me) {
    15. if (me->button()) {QFrame::mouseReleasedEvent(me); return;}
    16.  
    17. // here emit released and click signal if clicked... if not just call mouseReleasedEvent
    18. // from the base class and forget about clicked, if clicked...
    19.  
    20. // Anyway each widget receives those events, not only QFrame....
    21. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Adding click event to QFrame

    Quote Originally Posted by doc_ds View Post
    Reason not to use QPushButton::flat ist that QPushButton is atomic widget, not everything goes inside of it, and QFrame is just a frame, so basically surrounding the all widgets inside of it.
    I think that this has its own problems however, the most notable being that you would have to make sure that a mousePressEvent is propagated to the QFrame (per the OP's intent) rather than intercepted by any widgets placed in the QFrame?

Similar Threads

  1. Adding qframe with widgets to status bar
    By binaural in forum Newbie
    Replies: 4
    Last Post: 28th May 2010, 14:14
  2. Click SIGNAL on QFrame
    By sosanjay in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2009, 09:14
  3. pushButton click event
    By aj2903 in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 11:19
  4. click Event on Title Bar
    By anupamgee in forum Qt Programming
    Replies: 1
    Last Post: 26th May 2009, 17:12
  5. On click event for a QPixmap
    By rishid in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2008, 16:12

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.