当前位置:网站首页>Right click menu of QT
Right click menu of QT
2022-07-02 08:50:00 【Code pirate captain】
Qt QWidget Right click menu
QWidget And inheriting its class Qt Class by using void setContextMenuPolicy(Qt::ContextMenuPolicy) Enumeration settings right-click menu ,Qt::ContextMenuPolicy The enumeration of includes NoContextMenu,DefaultContextMenu,ActionsContextMenu,CustomContextMenu,PreventContextMenu Five types .
| enumeration | type |
|---|---|
| Qt::NoContextMenu | Part right-click menu , The processing of the right-click menu will be transferred to the parent of the part . |
| Qt::PreventContextMenu | There is no right-click menu for components , And NoContextMenu contrary , Processing is not deferred to the parent of the part . This means that all right mouse button events are guaranteed to pass QWidget::MousePresseEvent() and QWidget::mouseReleaseEvent() Passed to the widget itself . |
| Qt::DefaultContextMenu | Call the... Of the part QWidget::contextMenuEvent() The handler . |
| Qt::ActionsContextMenu | The component will QWidget::actions() Display as context menu . |
| Qt::CustomContextMenu | Components send QWidget::customContextMenuRequested() The signal . |
DefaultContextMenu Use
Set up DefaultContextMenu After the type , Rewritable contextMenuEvent(QContextMenuEvent *event) event , Call menu
void ZPushButton::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *mpMenu = new QMenu(this);
QAction* m_actionOne = new QAction(this);
QAction* m_actionTwo = new QAction(this);
QAction* m_actionThree = new QAction(this);
m_actionOne->setText("ActionOne");
m_actionTwo->setText("ActionTwo");
m_actionThree->setText("ActionThree");
mpMenu->addAction(m_actionOne);
mpMenu->addAction(m_actionTwo);
mpMenu->addAction(m_actionThree);
mpMenu->exec(QCursor::pos());// Displays... At the current mouse position
}
ActionsContextMenu Use
Use Qt::ActionsContextMenu, Add... Directly to the class QAction
setContextMenuPolicy(Qt::ActionsContextMenu);
QAction* m_actionOne = new QAction(this);
QAction* m_actionTwo = new QAction(this);
QAction* m_actionThree = new QAction(this);
m_actionOne->setText("ActionOne");
m_actionTwo->setText("ActionTwo");
m_actionThree->setText("ActionThree");
addAction(m_actionOne);
addAction(m_actionTwo);
addAction(m_actionThree);
connect(m_actionOne, SIGNAL(triggered()), this, SLOT(actionOneSlot()));
connect(m_actionTwo, SIGNAL(triggered()), this, SLOT(actionTwoSlot()));
connect(m_actionThree, SIGNAL(triggered()), this, SLOT(actionThreeSlot()));
Add the above code to the constructor of the form part , You can call the right-click menu .
CustomContextMenu Use
setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
connect(this,&ZPushButton::customContextMenuRequested,[this](const QPoint &pos){
qDebug()<<"pos:"<<pos;
QMenu *mpMenu = new QMenu(this);
QAction* m_actionOne = new QAction(this);
QAction* m_actionTwo = new QAction(this);
QAction* m_actionThree = new QAction(this);
m_actionOne->setText("ActionOne");
m_actionTwo->setText("ActionTwo");
m_actionThree->setText("ActionThree");
mpMenu->addAction(m_actionOne);
mpMenu->addAction(m_actionTwo);
mpMenu->addAction(m_actionThree);
mpMenu->exec(QCursor::pos());// Displays... At the current mouse position
});
边栏推荐
- c语言自定义类型——结构体,位段(匿名结构体,结构体的自引用,结构体的内存对齐)
- Sqli labs (post type injection)
- Aneng logistics' share price hit a new low: the market value evaporated by nearly 10 billion yuan, and it's useless for chairman Wang Yongjun to increase his holdings
- Gateway is easy to use
- 整理秒杀系统的面试必备!!!
- 选择排序和插入排序
- Minecraft group service opening
- HCIA - application layer
- sqli-labs第12关
- OpenFeign 简单使用
猜你喜欢

Linux binary installation Oracle database 19C

sqli-labs第2关

Linux安装Oracle Database 19c RAC

Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
![[blackmail virus data recovery] suffix Crylock blackmail virus](/img/b2/8e3a65dd250b9194cfc175138c740c.jpg)
[blackmail virus data recovery] suffix Crylock blackmail virus

kubeadm部署kubernetes v1.23.5集群

Honeypot attack and defense drill landing application scheme
![[blackmail virus data recovery] suffix Rook3 blackmail virus](/img/46/debc848d17767d021f3f41924cccfe.jpg)
[blackmail virus data recovery] suffix Rook3 blackmail virus

What is SQL injection

Qt——如何在QWidget中设置阴影效果
随机推荐
Sqli labs level 8 (Boolean blind note)
Web security -- Logical ultra vires
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
zipkin 简单使用
C# 将网页保存为图片(利用WebBrowser)
HCIA - data link layer
Sqli labs level 12
Minecraft air Island service
Dip1000 runaway
sqli-labs(POST类型注入)
Data asset management function
Minecraft install resource pack
Benefits of ufcs of D
sqli-labs第12关
Web技术发展史
C language replaces spaces in strings with%20
[flask] ORM one-to-one relationship
Makefile Fundamentals
Linux二进制安装Oracle Database 19c
Honeypot attack and defense drill landing application scheme