Results 1 to 2 of 2

Thread: QMenu on hover leave issue

  1. #1
    Join Date
    Aug 2017
    Qt products
    MacOS X Windows

    Default QMenu on hover leave issue

    Hi all, real newbie here. I'm working with a custom qGraphicsItem. When i hover over it i display a contact menu. Works great

    Qt Code:
    1. void pieces::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
    2. {
    5. myMenu->clear();
    6. setCursor(Qt::ClosedHandCursor);
    7. sandbox *myScene = dynamic_cast<sandbox *>(scene());
    8. if(myScene->mode()==sandbox::ModeMakeConnection)
    9. {
    10. QAction action1("EchoConnect", this);
    11. myMenu->addAction(&action1);
    12. myMenu->exec(QPoint(event->screenPos().x(),event->screenPos().y()));
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    however i'm trying to close it when i hover off. Running into issue here. I can't call the QGraphicsItem's hover leave because my focus is on the menu. so i'm trying to connect to qMenu's leaveEvent and failing. Here's what i'm trying:

    Qt Code:
    1. myMenu = new QMenu();
    2. connect(myMenu, SIGNAL(QWidget::leaveEvent(QEvent* event)), this, SLOT(popupLeave()));
    To copy to clipboard, switch view to plain text mode 

    but i get QObject::connect: No such signal QMenu::QWidget::leaveEvent(QEvent* event)

    Any pointers??

    Thanks in advance

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 864 Times in 851 Posts
    Qt products

    Default Re: QMenu on hover leave issue

    Any pointers??
    Yes, first use the correct syntax for the connect() statement:

    Qt Code:
    1. connect(myMenu, SIGNAL(leaveEvent(QEvent*)), this, SLOT(popupLeave()));
    To copy to clipboard, switch view to plain text mode 

    but in your case, this won't solve the problem. Your problem is you are trying to connect a slot to something that is not a signal. QWidget::leaveEvent() is an ordinary protected member function, not a signal. Even though there are several variations on the QObject::connect(), in all cases the first method in the connect() must be declared as a signal in the class definition. The method used as a slot can be any member function of the receiver, even a lambda.

    If you are trying to implement a context menu, then the QGraphicsItem::contextMenuEvent() exists for exactly that purpose.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 18th January 2016, 06:27
  2. Mouse hover issue in qt 4.7
    By qtuser123 in forum Qt Programming
    Replies: 0
    Last Post: 24th September 2012, 10:37
  3. hover event issue
    By sajis997 in forum Newbie
    Replies: 0
    Last Post: 1st August 2011, 18:14
  4. QPushbutton leave event
    By mikec in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2010, 09:38
  5. [Style Sheet] QMenu::item:hover bug
    By spud in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2007, 15:11

Tags for this Thread


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.