Results 1 to 10 of 10

Thread: Creating click events for label

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Creating click events for label

    Can someone point me in the right direction of making a click-able label? I'm working with some code I found on a site, but I'm not converting it right from key event to most events...

    Qt Code:
    1. class ClickLabel : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5.  
    6. protected:
    7. bool eventFilter(QObject *obj, QEvent *event);
    8. };
    9.  
    10. bool ClickLabel::eventFilter(QObject *obj, QEvent *event)
    11. {
    12. if (event->type() == QEvent::MouseButtonPress) {
    13. QMouseEvent *MouseEvent = static_cast<QMouseEvent *>(event);
    14. qDebug("MouseClicked", MouseEvent->clicked());
    15. return true;
    16. } else {
    17. // standard event processing
    18. return QObject::eventFilter(obj, event);
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 


    errors

    error: invalid static_cast from type 'QEvent*' to type 'QMouseEvent*'
    error: invalid use of incomplete type 'struct QMouseEvent'
    error: forward declaration of 'struct QMouseEvent'

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Creating click events for label

    Qt Code:
    1. #include <QMouseEvent>
    2.  
    3. class ClickLabel : public QObject
    4. {
    5. Q_OBJECT
    6. ....
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating click events for label

    Is it easy to inherit the functionality of the QLabel class into the new class, so that I can easily use the same features like set text, and stuff of that nature?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Creating click events for label

    Yes, inherit from QLabel and not QObject.

Similar Threads

  1. Replies: 0
    Last Post: 17th March 2011, 19:38
  2. Click events
    By Maluko_Da_Tola in forum Newbie
    Replies: 0
    Last Post: 26th August 2010, 01:05
  3. how to get the position of mouse click on a label
    By qt_user in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2010, 09:14
  4. Detect click on QTableWidget label
    By Darthspawn in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2010, 10:50
  5. close window when click on a label
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 07:35

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.