I like the default handling/layout that adding a dock widget to the main window with addDockWidget() provides. Specifically the following:
Uses a QSplitter (I assume) which allows user to resize 2 dock widget and central widget.
Cannot shrink the dock widget below it's minimum size hint.
When dragging the size of the entire window the dock widget stays it's original size (i.e. it's different than dragging the splitter). Thus, the central widget grows when dragging the entire window instead of both dock and central widget growing.
I'd like to mimic this behavior, but on a QDialog since I can't just call addDockWidget(). I'm not really concerned about being able to drag the dock widget around and drop it on other corners, etc. I just want a QLayout setup that can do the above 3 things.
You can use a QMainWindow instead of a QDialog in order to get dockwidget functionality for a dialog. You should not notice any difference in performace between QMainWindow and QDialog.
Related
I am building an app using pyqt5, where I have a central widget and several dockable widgets. The central widget consists of a QTabWidget and a pyforms ControlPlayer widget.
Whenever I resize any of the dockable widget and switch a tab in my QTabWidget, the dockable widgets get resized to their initial sizes. However, if I float around one of the dockable widgets and dock it right back then they don't resize, which is desirable for my application.
Can someone explain to me what is happening here? My guess is that some flag is being set on the central widget when I float the dock window, but I'm not sure which one
I came across the same in the manner: resized QDockWidgets snap back to their original form after the MainWindow is resized or something in my dockwidget is changed
(in my case: when tabs change within the dockWidget.)
This is, unfortunately, a bug and is not your fault.
I didn't find any fix for PyQt. The C++Community has a fix ready, but I guess I'm just to inexperienced in python to transfer that, since the self.resizeDocks doesn't seem to take my arguments.
see also:
https://bugreports.qt.io/browse/QTBUG-65592
or
QDockWidget splitter jumps when QMainWindow Resized
I have a QTreeView widget placed inside a QDockWidget:
I want to set the properties of the QTreeView, that it automatically fills the whole available client drawing area (similar as WinForms DockFill property).
How can this be achieved with the QT-Designer?
Note: I've been playing around with the QTreeViews sizePolicy properties. If these are set to Expanding (as is the default) the accepted answer works out out of the box.
In Qt Designer, right-click the dock-widget, and then select Lay out -> Lay Out Vertically from the menu. Or you can just click on the dock-widget to select it, and then use the equivalent layout toolbar buttons.
If you want to maximise the space taken up by the tree-view, select the first child widget of the dock widget (it will probably be shown as dockWidgetContents in the Object Inspector pane). Then scroll down to the bottom of the Property Editor, and reset all the margins to zero.
I have a QHBoxLayout, and it has 2 QVBoxLayouts on it one near the other.
Each layout has widgets, and I wonder how to make this layout resizable (the user can change the width) ?
Use a QSplitter. Create a couple of top-level container widgets for your vbox layouts, and then use the splitter's addWidget method to add the widgets to the splitter. The splitter's orientation is horizontal by default, so the vboxes will appear side by side.
I would like to create a Qwidget with a large number of square QPushButtons. I would like those buttons to be organised into a mosaic layout. Whenever the window is resized, the mosaic widget should be resized and the buttons re-ordered accordingly to fill in the width. Buttons that cannot fit within the area, can be viewed by scrolling the widget vertically.
Is there a Qt4 Layout that allows me to do this easily? What is the best / easiest way to achieve this? Thanks.
You could use the flow layout (from Qt examples) inside a resizable QScrollArea.
Use a QGridLayout in a QScrollArea.
I have this main window on which I would like to put 2 widgets on the same space, i.e. when the user clicks a button then one of the widgets should come up front and the other be hidden and then change places when clicking another button.
My Widget are of different types: one is a QGLWidget and the other one is a QGraphicsView.
How could I put these 2 widgets on the same place?
Use QStackedWidget. Qt Doc says that :
The QStackedWidget class provides a stack of widgets where only one
widget is visible at a time.