Dmitry Bardyshev
Dmitry Bardyshev

Reputation: 95

How can I insert an image in a QMenu?

I tried to make it like this :

QWidgetAction *labelAct = new QWidgetAction(screenMenu);
QLabel *label = new QLabel("sadas", screenMenu);
labelAct->setDefaultWidget(label);
screenMenu->addAction(labelAct);

but label is empty:

empty label

Upvotes: 1

Views: 1491

Answers (2)

p.i.g.
p.i.g.

Reputation: 2995

Why don't you use just the void setIcon( const QIcon& icon ) function of the QAction.

labelAct->setIcon( QIcon( "icon path" ) );

Upvotes: 0

you can use QLabel setPixmap() to set a pixmap

Something like:

QWidgetAction *labelAct = new QWidgetAction(screenMenu);
QLabel *label = new QLabel("sadas", screenMenu);
QPixmap mypix (":/test.png");
label->setPixmap(mypix);
labelAct->setDefaultWidget(label);
screenMenu->addAction(labelAct);

Upvotes: 1

Related Questions