开发者

Is it possible to add a menu bar to a widget

开发者 https://www.devze.com 2022-12-23 06:31 出处:网络
I woul开发者_Python百科d like to add a QMenuBar to a window of my program (not the QMainWindow) from QtDesigner but I do not see this widget in there and it seems the only way to do this from designer

I woul开发者_Python百科d like to add a QMenuBar to a window of my program (not the QMainWindow) from QtDesigner but I do not see this widget in there and it seems the only way to do this from designer is to use a mainwindow. Would I absolutely need to create this QMenu by hand coding it. Is it possible/ok to instead add a QMainwindow that is actually declared inside my main QMainwindow?


Why don't you use a second instance of QMainWidow or make the widget which need to receive the menu bar inherit from it.


There is tricky way to add QMenuBar anywhere. You can add simple widget in designer and then edit your ui file with simple text editor. You can find your widget by name and replace "QWidget" with "QMenuBar". After that you can reload ui file in designer and work with QMenuBar same way as if was on QMainWindow


Right click on widget in Object panel (where you see objects in tree view) and select Create Menu Bar. That's it.

0

精彩评论

暂无评论...
验证码 换一张
取 消