Results 1 to 13 of 13

Thread: How to do auto show/hide a widget in Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to do auto show/hide a widget in Qt

    Try using QEasingCurve::InOutQuint, and you can use different setDuration() while showing and while hiding(), this will ensure a slow smotth show, and quick hide.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  2. The following user says thank you to Santosh Reddy for this useful post:

    rawfool (27th May 2013)

  3. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to do auto show/hide a widget in Qt

    Now a small hiccup, after adding this auto-hide menu, if there is any widget that's overlapping the menu widget's region, then it's not responding and also the menu widget is shown under it.
    So if there is any other widget, and when the menu widget is shown, it's moving under visible widget.
    Is there anything like bring-to-front, etc, for bringing the menu widget to front. I tried setFocus(); but didn't solve the issue.

    How do I bring the menu widget to top-most visible area and mouse hover on the other widgets in that page should be relative ?

    I tried, but didn't work as expected:
    Qt Code:
    1. menuWidget->setWindowFlags(Qt::WindowStaysOnTopHint); // menu widget is child of mainwidget(central Widget of main window) and is not in layout
    2. menuWidget->raise();
    3. frmWidget->setWindowFlags(Qt::WindowStaysOnBottomHint);
    To copy to clipboard, switch view to plain text mode 

    EDIT: I'm able to bring it on top by adding the menubar at last. But the mouse move on the bottom widget isn't giving response to this to hide the menu widget, when out of the specified region.

    Thank you.
    Last edited by rawfool; 29th May 2013 at 12:40.

  4. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to do auto show/hide a widget in Qt

    EDIT: I'm able to bring it on top by adding the menubar at last. But the mouse move on the bottom widget isn't giving response to this to hide the menu widget, when out of the specified region.
    Then hide() the menu widget when the menu widget reveices QEevnt::Leave event, which indicated that mouse has left the menu widget
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    rawfool (30th May 2013)

  6. #4
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to do auto show/hide a widget in Qt

    This is how I did that, but now the menu widget is not hiding,

    Qt Code:
    1. bool eventFilter(QObject * object, QEvent * event)
    2. {
    3. if((parent() == object) & (event->type() == QEvent::MouseMove))
    4. {
    5. QMouseEvent * mouseEvent = static_cast<QMouseEvent *>(event);
    6. if(mouseEvent->pos().x() < 80)
    7. {
    8. if(isHidden() && (mAnimation->state() != mAnimation->Running))
    9. {
    10. mAnimation->setStartValue(QRect(-3, 80, 0, 250));
    11. mAnimation->setEndValue(QRect(0, 80, 70, 250));
    12. disconnect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
    13. mAnimation->start();
    14. show();
    15. }
    16. }
    17. else if((mouseEvent->type() == QEvent::Leave) && (mAnimation->state() != mAnimation->Running))
    18. {
    19. qDebug("Inside QEvent::Leave"); // This message is not getting printed
    20. if(!isHidden())
    21. {
    22. mAnimation->setEndValue(QRect(-3, 80, 0, 250));
    23. mAnimation->setStartValue(QRect(0, 80, 70, 250));
    24. connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
    25. mAnimation->start();
    26. }
    27. }
    28. }
    29. return QWidget::eventFilter(object, event);
    30. }
    To copy to clipboard, switch view to plain text mode 
    I think my else if is wrong. Kindly help me correct this. Thank you

  7. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to do auto show/hide a widget in Qt

    QEvent::MouseMove event is received for parent widget, and QEvent::Leave should be received for self widget, so move the else if out of if(parent() ==...., and also make suere to install the event filter on self. (this->installEventFilter(this);
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  8. The following user says thank you to Santosh Reddy for this useful post:

    rawfool (30th May 2013)

  9. #6
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to do auto show/hide a widget in Qt

    Thanks a lot. All the issues related to this are solved for now.

  10. #7
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to do auto show/hide a widget in Qt

    Just a small note, as this may help someone who do this. After doing this -
    Quote Originally Posted by Santosh Reddy View Post
    QEvent::Leave should be received for self widget ..
    it hides the widget.
    A small problem persisted and it was - if there's a layout and widgets in the mouse-hover area, then the trigger didn't reach the menu widget. I solved it by making the layout and widgets as children to the same parent to which menu widget was and enabled mouse tracking true for the widget(s) on the way and this solved my problem.
    Thank you.

Similar Threads

  1. Replies: 10
    Last Post: 20th April 2015, 22:24
  2. Replies: 1
    Last Post: 9th December 2011, 03:42
  3. Replies: 4
    Last Post: 2nd October 2011, 00:20
  4. Replies: 2
    Last Post: 8th February 2011, 18:07
  5. MAC: Getting Dock widget show/hide events
    By jay in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2010, 08:07

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.