Results 1 to 13 of 13

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    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

    I tried QGraphicsView & QGraphicsSCene, but I not working as I expected. I'm calling the widget to show after 3 seconds using a singleshot timer. But I see the widget is flashing and disappearing.
    Below is the way how I implemented see how it comes out.

    Qt Code:
    1. #include "ccentralwidget.h"
    2. #include <QGraphicsScene>
    3. #include <QGraphicsView>
    4. #include <QTimer>
    5.  
    6. CMainWidget::CMainWidget(QWidget *parent) :
    7. QWidget(parent)
    8. {
    9. this->setStyleSheet("background-color: lightGray;");
    10. this->setFixedSize(650, 450);
    11. m_widget = new CMenuWidget();
    12.  
    13. QTimer::singleShot(3000, this, SLOT(showMenuWidget()));
    14. }
    15.  
    16. CMainWidget::~CMainWidget()
    17. {
    18. delete m_widget;
    19. }
    20.  
    21. void CMainWidget::showMenuWidget()
    22. {
    23. scene.addWidget(m_widget);
    24. scene.setSceneRect(0, 30, 60, 250);
    25.  
    26. QGraphicsView view(&scene);
    27. view.show();
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 

    ---------------------------------------------------------------------------------------------

    And I tried it using QPropertyAnimation also, but it's giving some error/warning messages output.
    I'm calling the below slot in singleshot timer the same way as shown in the above code.
    Qt Code:
    1. void CCentralWidget::showMenuWidget()
    2. {
    3. QPropertyAnimation *animation = new QPropertyAnimation(m_widget, "MyMenu");
    4. animation->setDuration(2000);
    5. animation->setStartValue(QRect(0, 0, 100, 30));
    6. animation->setEndValue(QRect(250, 250, 100, 30));
    7.  
    8. animation->start();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //Output Message:
    2. QPropertyAnimation: you're trying to animate a non-existing property MyMenu of your QObject
    To copy to clipboard, switch view to plain text mode 

    I need to show/hide the widget the same way how the left app menu widget is shown/hidden on mouse move to the left area in Ubuntu unity and this kind of graphics can be seen a text editor called Scribes.
    So for now I'm trying to achieve the same transition on singleshot timer, later I call it in movemove event.
    Kindly help me. Thank you.
    Last edited by rawfool; 27th May 2013 at 07:05.

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
  •  
Qt is a trademark of The Qt Company.