How to add menu bar and toolbar into the qdialog - qt

Exists any solution how to add menu or tool bar into the QWidget dialog?
I making something like ERP system. There are many windowses opening from others windowses. It's important that one (parent) window waiting for choices in children window. And in the chidren window sometimes I need toolbars and menu bars...
Problem is, that
new child QMainWindow have no exec() function. It cause that parent window no waiting for finishing choices in the child.
new child QDialog have no menu or toll bar.
Exists any solution (without events)? Solution how to add menu or tool bar to QDialog, or solution how to open new qmainwindow with waiting mode myMainWindow->exec()?

Ok. I find solution.
I used QDialog. Menu or tab bar will be added as:
anylayout->addWidget(tabbar); or anylayout->setMenuBar(tabbar);
Thx for answer by Chris Kawa:
The difference is that setMenuBar places the widget outside of the layout content, so the top margin of the layout is below the bar . With addWidget the bar is added as a layout content, so it respects the margins (controlled by setContentsMargins).
For menus and toolbars we usually want them to stick to edges without a gap, so the setMenuBar method is more appropriate for it.

Related

How to prevent QMenu from going out of the main window

I have a QMenubar inside QMainWindow. I have set it to be displayed on the right corner using setCornerWidget. But the menu items are going out of the main window. How can I prevent the menu to be displayed within the window?
I have already tried menu->setLayoutDirection(Qt::RightToLeft) which is giving me a mirror image of the current menu display as seen below, but that does not look good to me. Is there a way to keep the direction from Qt::LeftToRight and still be able to contain the menu inside the window?

How can I allow user resize on elements within the window using Qt designer?

I want to allow a user using my application to be able to drag a boundary between two widgets in my window which will resize the two (i.e. you drag it down and the top one will get bigger while the bottom gets smaller, and vice-versa).
Is there anything in Qt designer that will allow a user to resize an element in the window, within certain constraints?
Thank you
What you're describing is called a QSplitter widget. In Qt Designer, you can create one by selecting 2 or more widgets, and then clicking the splitter button on the toolbar at the top. It's in the same location as the layout buttons. It will place those widgets inside a QSplitter. You still need to place the splitter widget inside another layout. It will create a handle between them to let you resize the portion that each widget gets.
You're looking for the QDockWidget. It can do all that you described above and more. The user can dock the widget to different sides of the window, changing which widget is on the top or bottom. You can customize the minimum and maximum sizes, as well as default sizes.

QT layout manager does not recover space when hiding widget until window is moved

I am using Qlabels to plot some graphs and images (via setpixmap).
My basic layout is:
QVBoxlayout main layout via qdialog's setlayout.
QHboxlayout (array of QLabels)
Qlabel expandedPlot (optional expanded plot of one of the above QLabels)
QLabel mainImage Main image display
Within the QDialogs re-implemented keypress event handler, I hide()/show() the expanded plot. When I hide() the expandedPlot, the layoutmanager recovers about 1/2 of the vertical usage. Then when I drag the window, the layout manager recovers the remainder of the vertical space (as if there was no item present).
How can I force the behavior of moving the window? I want the layout manager to completely recover the vertical space.
I am using Qt 5.6 on windows, but want cross-platform solutions.
Thank you, mike
Because laying out the widget is quite expensive, Qt doesn't always do it. If you change the size of enclosed widgets you are likely to need to call updateGeometry on them to trigger the enclosed layout manager to re-layout. But if you hide the widget, updateGeometry does nothing. In that case you need to call adjustSize on the parent widget, which will then trigger the re-layout.

QT - sliding widget

I'm new in QT interfaces. I would like to create sliding widget in my desktop application (no QML). Idea is to create sliding menu like facebook component on some web pages.
For example:
I have main window and I want to have small part of widget on the right window edge
When mouse move on this widget (or click on it) then this widget slide to show all its content.
I know how to create animation and handle mouse events. There is a lot of examples about it. The problem is that this menu widget should not interact with other layouts and widgets. I mean, main window has root horizontal layout and I don't know how to exclude this widget from it and place widget in front of all widgets on main window. Are exists some layers in QT?
You could accomplish similar functionality by overlaying a custom QDockWidget. This widget could then float above the other widgets in a fixed position relative to your mainwindow. Connect the main window's resize/move events to slots on your QDockWidget that keeps their positions in sync.

Central QWidget [Qt]

I have main window and in this window I have QListWidget. I want this list to be central widget in the main window and I know that I can do that by writing code like setCentralWidget(QWidget*) and it works (list is spread on the whole mainwindow) but this isn't reflected in designer when the list is still in this same position and has the same size. Is there any way to make it so the change is visible in designer as well as in the code?
Thank you.
In Designer, right click on an area of the form next to the QListWidget, then choose Layout->Layout Horizontally (or vertically, almost anything is acceptable).
I figured it out. In order to do so I had to choose grid layout for main window and sizePolicy for list as Prefered.

Resources