Results 1 to 2 of 2

Thread: QMenu on hover leave issue

  1. #1
    Join Date
    Aug 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    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. {
    3.  
    4.  
    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
    Location
    Alameda, CA, USA
    Posts
    4,022
    Thanks
    233
    Thanked 640 Times in 630 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    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, 05:27
  2. Mouse hover issue in qt 4.7
    By qtuser123 in forum Qt Programming
    Replies: 0
    Last Post: 24th September 2012, 09:37
  3. hover event issue
    By sajis997 in forum Newbie
    Replies: 0
    Last Post: 1st August 2011, 17:14
  4. QPushbutton leave event
    By mikec in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2010, 08:38
  5. [Style Sheet] QMenu::item:hover bug
    By spud in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2007, 14:11

Tags for this Thread

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.