Qt 覆盖标题栏和菜单栏?

发布于 2024-12-05 04:03:39 字数 336 浏览 0 评论 0原文

我开始了一个一直在计划的项目,我有一个简单的问题。

我希望拥有尽可能多的屏幕空间。为此,我需要使标题栏变薄,并且我还想让菜单栏隐藏,直到将其悬停在其上。

是否有一个功能可以快速缩小标题栏。

我很确定我需要使用 setMenuWidget() 创建自定义菜单栏,然后​​添加标签、信号和其他有趣的菜单内容。我说得对吗,除了设置所有标签和连接的函数之外,我还需要 setMenuWidget() 吗?我是否必须在类中创建一个变量,或者我可以创建一个名为 setUpMenuBar() 的函数吗?

我试图尽我所能地表达这一点。有时我的问题有点模糊,所以如果你清楚的话,就问吧。

谢谢!

I started on a project that I've been planning and I have a quick question.

I want to have as much screen space as possible. To do this I need to make the title bar thinner and I also want to have the menu bar hide until it is hovered over.

Is there a function that would allow be to quickly just shrink the title bar.

I'm pretty sure I need to use setMenuWidget() to create a custom menu bar, and then just add the labels, signals, and the other fun menu stuff. Am I right, is setMenuWidget() all I need beside the function that sets all of the labels and connections? Would I have to create a variable in the class, or could I just create a function called setUpMenuBar()?

I tried to word this as well as I could. Sometimes my questions are a bit vague so if you clarity, just ask.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场信仰旅途 2024-12-12 04:03:39

使用全屏模式摆脱标题栏。我认为这比看起来不标准的细标题栏更加用户友好。

Use full screen mode to get rid of the title bar. I think that would be much more user friendly than a nonstandard looking thin title bar.

橘味果▽酱 2024-12-12 04:03:39

您的自定义菜单栏小部件是否需要成员变量仅取决于您对它的使用。如果您所做的只是创建菜单,那么不,您不需要为其保留成员变量。 “QMainWindow 获得了 menuBar 指针的所有权,并在适当的时间将其删除。”

MyMainWindow::setUpMenuBar() {
    MyCustomMenuBar * menubar = new MyCustomMenuBar;
    // add all the menus
    setMenuWidget( menubar );
}  

您甚至可以稍后检索指向菜单栏的指针:

MyCustomMenuBar * menubar = qobject_cast<MyCustomMenuBar *>( menuWidget() );

如果您更频繁地需要此指针,您可以重写 MyMainWindow::menuWidget() 或将该指针保存为成员。

Whether or not you need a member variable for your custom menu bar widget depends only on your use of it. If all you do is create the menu, then no, you don't need to keep a member variable for it. "QMainWindow takes ownership of the menuBar pointer and deletes it at the appropriate time."

MyMainWindow::setUpMenuBar() {
    MyCustomMenuBar * menubar = new MyCustomMenuBar;
    // add all the menus
    setMenuWidget( menubar );
}  

You can even retrieve a pointer to menubar later:

MyCustomMenuBar * menubar = qobject_cast<MyCustomMenuBar *>( menuWidget() );

If you need this pointer more often, you can either override MyMainWindow::menuWidget() or save the pointer as a member.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文