博客
关于我
Qt 给QWidget添加工具栏
阅读量:609 次
发布时间:2019-03-13

本文共 493 字,大约阅读时间需要 1 分钟。

在Qt应用程序中创建工具栏和弹出菜单,可以按照以下步骤进行:

首先,创建主窗口布局。使用 QVBoxLayout 定义布局,并设置适当的间距和边缘值。接着,新建一个 QToolButton 并设置其文本内容为“Number”。确保工具按钮的弹出模式为 MenuButtonPopup,这可以通过调用 setPopupMode 方法来实现。

然后,创建一个 QMenu 对象,将两个 QAction 对象添加到其中。一种行动创建了带有文本“11”的选项,另一种则创建了带有文本“22”的选项。将菜单分配给工具按钮,确保菜单正确地与工具按钮关联。

接下来,创建工具栏,并将工具按钮添加到工具栏中。将工具栏添加到主窗口的布局中,按照你想要的位置放置。此外,创建一个额外的 QWidget 并添加到布局中,以容纳其他可能的组件。

最后,设置布局的比例参数,确保工具栏位于窗口的顶部。按照上述步骤编写代码后,应能在应用程序中看到一个带有工具栏的用户界面,其中工具栏顶部显示“Number”按钮,点击后弹出菜单。

这样的布局设置和组件配置方法可以帮助开发者在Qt应用程序中轻松创建工具栏和弹出菜单。

转载地址:http://audaz.baihongyu.com/

你可能感兴趣的文章
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>