Results 1 to 6 of 6

Thread: How to handle mousehover event on a label?

  1. #1
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to handle mousehover event on a label?

    While mouse hovers on a label, then a window with a clickable link pops up.
    When the link is clicked, or mouse leave the label, or mouse leave the popup window,
    the popup window will be closed.

    How to implement it?

    Any help is appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to handle mousehover event on a label?

    Reimp the handlers QWidget::enterEvent() and QWidget::leaveEvent(). Open and close the pop up there.

  3. #3
    Join Date
    Dec 2010
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to handle mousehover event on a label?

    Quote Originally Posted by Lykurg View Post
    Reimp the handlers QWidget::enterEvent() and QWidget::leaveEvent(). Open and close the pop up there.
    Thanks for your advice.
    I tried, have no lucky.
    Can you post the codes up if possible?
    Thanks again.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to handle mousehover event on a label?

    what have you tried so far and how does your code look like?

  5. #5
    Join Date
    Jan 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to handle mousehover event on a label?

    You should make a new class inheriting from QLabel class.
    In the new class, put the declaration of Widget events under the "signals:".
    Then, connect the signals to your slots.
    For example:

    class myClass : public QLabel
    ...
    signals:
    void mouseReleaseEvent(QMouseEvent *);
    ...
    public slots:
    void mySlot();

    in the constructor:
    connect(this, SIGNAL(mouseReleaseEvent(QMouseEvent*)), this, SLOT(mySlot()));

  6. #6
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: How to handle mousehover event on a label?

    Quote Originally Posted by dominate View Post
    You should make a new class inheriting from QLabel class.
    In the new class, put the declaration of Widget events under the "signals:".
    Then, connect the signals to your slots.
    For example:

    class myClass : public QLabel
    ...
    signals:
    void mouseReleaseEvent(QMouseEvent *);
    ...
    public slots:
    void mySlot();

    in the constructor:
    connect(this, SIGNAL(mouseReleaseEvent(QMouseEvent*)), this, SLOT(mySlot()));
    That is totally wrong. You have to overload the mouseReleaseEvent. Not connect it to a slot.
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

Similar Threads

  1. HOw to handle checkBox event occured in qlistwidget
    By sanket.mehta in forum Qt Programming
    Replies: 0
    Last Post: 16th November 2010, 09:36
  2. Replies: 0
    Last Post: 15th June 2010, 09:12
  3. Replies: 3
    Last Post: 12th May 2010, 13:11
  4. Replies: 5
    Last Post: 3rd April 2010, 04:07
  5. mousehover event in QTreeWidgetItem
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 2
    Last Post: 29th March 2010, 07:20

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.