QTメインフォームの右ボタンからプルダウンメニューのポップアップ方法
From:
http://hi.baidu.com/qinpanke/blog/item/9b6441a60dd3409cd043584f.html
QTメインフォームの右ボタンからプルダウンメニューの方法(メインフォームの類名はCGuiMainwindowです):
http://hi.baidu.com/qinpanke/blog/item/9b6441a60dd3409cd043584f.html
QTメインフォームの右ボタンからプルダウンメニューの方法(メインフォームの類名はCGuiMainwindowです):
void CGuiMainwindow::contextMenuEvent(QContextMenuEvent* e)
{
QMenu *menu = new QMenu();
menu->addSeparator();
menu->addSeparator();
menu->addAction(Act_Maxsize);
menu->addSeparator();
menu->addSeparator();
menu->addAction(Act_Normal);
menu->addSeparator();
menu->addSeparator();
menu->exec(e->globalPos());
delete menu;
}
Act_Maxsize Act_Normal QAction 。 :
QAction* Act_Maxsize;
QAction* Act_Normal;
Act_Maxsize = new QAction(tr("XML"), this);
Act_Maxsize->setIcon(QIcon("Resources/logo.png"));
Act_Normal = new QAction(tr("SHOW"), this);
Act_Normal->setIcon(QIcon("Resources/logo.png"));
connect(Act_Maxsize, SIGNAL(triggered()), this, SLOT(ADDChange()));
connect(Act_Normal, SIGNAL(triggered()), this, SLOT(XMLChange()));
QT ( QTreeWidget ):
connect(moduleTree,SIGNAL(itemPressed(QTreeWidgetItem *, int)),
this,SLOT(SlotItemClicked(QTreeWidgetItem *, int)));
void CGuiMainwindow::SlotItemClicked(QTreeWidgetItem *item, int column)
{
if (qApp->mouseButtons() == Qt::LeftButton)
{
return;
}
if (qApp->mouseButtons() == Qt::RightButton)
{
if (item->childCount() > 0)
{
return;
}
ShowMenu();
}
}
:
void CGuiMainwindow::ShowMenu()
{
QPoint pos;
QMenu menu(moduleTree);
QIcon myIcon("Resources/logo.png");
menu.addAction(myIcon,tr(" _1"));