PDA

View Full Version : image for a custom menu Item.......



Naveen
23rd February 2006, 06:29
Look at the code below......
I'm adding an item to the contextMenu like this.....where restore1() is a custom method.....

QMenu menu(this);
QAction *restore = menu.addAction(tr("&restore"));
restore->setShortcut(Qt::CTRL | Qt::Key_R);
connect(restore,SIGNAL(triggered()),this,SLOT(rest ore1()));

Until here its working fine but .....now i would like to add an Image before the context menu item (restore in this case.....) and not only that ......I want make the display of custom menu item(which is restore here) look BOLD...........

zlatko
23rd February 2006, 09:20
In qt3 examples available example menu which answer on your questions;)

jpn
23rd February 2006, 09:28
Icon and font are properties of QAction:

Icon:
http://doc.trolltech.com/4.1/qaction.html#icon-prop


restore->setIcon(QIcon("restore.png"));


Font:
http://doc.trolltech.com/4.1/qaction.html#font-prop


QFont font = restore->font();
font.setBold(true);
restore->setFont(font);