Qt override Title bar and menu bar?
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 开发者_StackOverflowI 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!
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.
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.
精彩评论