PDA

View Full Version : The QMenu will not show immediately, why?



koilin
20th July 2012, 05:02
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!

Jonny174
20th July 2012, 05:42
Show your code where you exec menu

axiula
21st May 2013, 11:43
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);
};

amleto
21st May 2013, 12:47
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.

axiula
22nd May 2013, 03:10
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.



void DisplayWindow::contextMenuEvent (QContextMenuEvent *event)
{
QCursor cur = this->cursor();
PopMenu *menu = new PopMenu(this);
QAction* activeAction = menu->exec(cur.pos());
}

.h file


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);
};