Results 1 to 5 of 5

Thread: The QMenu will not show immediately, why?

  1. #1
    Join Date
    May 2012
    Posts
    11
    Qt products
    Qt4

    Default The QMenu will not show immediately, why?

    When I pressed the right mouse button, I will let the QMenu.exec(). I could not see the menu immediately. After I moved the mouse, then the menu will show. Why? Could anyone give me an idea? How to find the problem. It's very difficulty to debug at this time. Thank you!

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The QMenu will not show immediately, why?

    Show your code where you exec menu

  3. #3
    Join Date
    Dec 2010
    Location
    China
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: The QMenu will not show immediately, why?

    I have met the same problem, let me show my code.

    QCursor cur = this->cursor();
    PopMenu *menu = new PopMenu(this);
    QAction* activeAction = menu->exec(cur.pos());

    class MyIconStyle : public QPlastiqueStyle
    {
    Q_OBJECT
    public:
    virtual int pixelMetric(PixelMetric metric, const QStyleOption * option, const QWidget * widget) const;
    };

    class MyMenu : public QMenu
    {
    Q_OBJECT
    public:
    explicit MyMenu(QWidget *parent);

    protected:
    MyIconStyle *m_pMyStyle;
    };

    class PopMenu : public MyMenu
    {
    Q_OBJECT
    public:
    explicit PopMenu(QWidget *parent);
    protected:
    QAction *action1;
    QAction *action2;

    //sub_menus

    QAction *sub_action_16[2];
    QAction *sub_action_24[2];

    QLabel *label_title;

    bool eventFilter(QObject *obj, QEvent *event);

    public slots:
    void triggeredDeal(QAction *action);
    };

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The QMenu will not show immediately, why?

    1) use code tags.
    2) just writing

    QCursor cur = this->cursor();
    PopMenu *menu = new PopMenu(this);
    QAction* activeAction = menu->exec(cur.pos());

    provides no context at all as to where and how your code is called.

    With that said, I don't know why you would be experiencing a delay before the menu is shown.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Dec 2010
    Location
    China
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: The QMenu will not show immediately, why?

    the PopMenu is a class derived the QMenu. In the contextMenuEvent of the DisplayWindow, the code is called . The menu is not immediately shown. After moved the mouse, then the menu will show. It's seem like a problem of render because the cpu is used for decoding the multi-channel
    realtime stream & the gpu is used for rendering the YUV on the DisplayWindow at the same time. I find that if I reduce the channels from 8 to 6,the popmenu is immediately shown.


    Qt Code:
    1. void DisplayWindow::contextMenuEvent (QContextMenuEvent *event)
    2. {
    3. QCursor cur = this->cursor();
    4. PopMenu *menu = new PopMenu(this);
    5. QAction* activeAction = menu->exec(cur.pos());
    6. }
    To copy to clipboard, switch view to plain text mode 

    .h file

    Qt Code:
    1. class MyIconStyle : public QPlastiqueStyle
    2. {
    3. Q_OBJECT
    4. public:
    5. virtual int pixelMetric(PixelMetric metric, const QStyleOption * option, const QWidget * widget) const;
    6. };
    7.  
    8. class MyMenu : public QMenu
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit MyMenu(QWidget *parent);
    13.  
    14. protected:
    15. MyIconStyle *m_pMyStyle;
    16. };
    17.  
    18. class PopMenu : public MyMenu
    19. {
    20. Q_OBJECT
    21. public:
    22. explicit PopMenu(QWidget *parent);
    23. protected:
    24. QAction *action1;
    25. QAction *action2;
    26.  
    27. //sub_menus
    28.  
    29. QAction *sub_action_16[2];
    30. QAction *sub_action_24[2];
    31.  
    32. QLabel *label_title;
    33.  
    34. bool eventFilter(QObject *obj, QEvent *event);
    35.  
    36. public slots:
    37. void triggeredDeal(QAction *action);
    38. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QMenu does not show icons from QAction
    By eumel1990 in forum Newbie
    Replies: 5
    Last Post: 10th September 2011, 10:57
  2. Icon in a QMenu doesn't show up on Linux
    By agarny in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2011, 14:58
  3. Hide and Show QMenu
    By febil in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2009, 09:31
  4. [+] does not show up immediately
    By yuriry in forum Qt Programming
    Replies: 4
    Last Post: 4th October 2008, 19:14
  5. How to show a "widget" immediately?
    By deweyjew in forum Newbie
    Replies: 2
    Last Post: 31st May 2006, 12:58

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.