Add QWidget above QToolBar in QMainWindow
-
Hello,
I have a QMainWindow with a central widget, left docked widget and a right docked widget.
I also have a toolbar at the top.Below screenshot depicts my current layout structure.
I would like to add a widget on top of the toolbar that would contain the user info like name, DOB etc.
Expected layout is as depicted by the below image
Is there a way to do it??
I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.
But it doesn't help.Note: Title widget here is not the "window title", i want to have a separate widget on top of toolbar.
Can anyone give me a heads up on this ? or is this atleast doable?
-
@Rizwan94 said:
I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.
That's close, but you need one extra step.
Create a plain QWidget, set a vertical layout on it, add your widget and toolbar to it and then use setMenuWidget() on your main window.EDIT: Or you can even make it simpler - just use your title widget directly as the menu bar.
-
@Rizwan94
Before someone else comes up with some clever way to achieve it....A
QMainWindow
has its layout as per https://doc.qt.io/qt-5/qmainwindow.html#details picture, and I don't see it offering you to change that framework. So using aQMainWindow
feels like a square peg & a round hole. Are you tied toQMainWindow
. If it's your own code and not tied, I'd have aQWidget
with the furniture bits added to it. Like I say, until someone says yours can be done with a one-liner onQMainWindow
.Another possibility is to try inherited
QWidget::setLayout()
on aQMainWindow
. Find out how they've laid it out, and insert your extra title widget before the toolbar ( how did you do your "added that layout above central widget"?). But don't blame me if it doesn't work or makes something go wrong! -
@Rizwan94 said:
I tried creating a vertical layout with title widget and toolbar, and added that layout above central widget.
That's close, but you need one extra step.
Create a plain QWidget, set a vertical layout on it, add your widget and toolbar to it and then use setMenuWidget() on your main window.EDIT: Or you can even make it simpler - just use your title widget directly as the menu bar.
-
Thanks @Chris-Kawa
Works like a charm!! -
@Rizwan94 May I ask what was your final implementation? I'm trying to setup a frameless window and add my title/close buttons on top of an existing QMainWindow (from .ui)
Thanks in advance