PyQt QDockWidget in a Layout is no more movable ...
Hi guys !
I m new to Qt and I am dealing with my first UI.
What I want to do is to have QDockWidgets into a ScrollArea and this scroll area is part of a QtabWidget so when I switch to tab2 I don't see my QDocksWidgets anymore ...
After typing few lines of code :
my QDockWidgets are going inside my QScrollArea I can dock them out and dock them back in but I can't move them when they are docked out...
I have had a look at some "dockWidgetFeatures" tried the "isFloating" but nothing seems to work ...
That's why I am writing this post, hopefully someone already dealt with that and can help me or just tell me that I am doing it the wrong way ...
here is a part of my code:
# create dock self.dock = QtGui.QDockWidget(self.selectedFunction, parent=self) # edit features self.dock.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures) self.setDockOptions(QtGui.QMainWindow.AllowNestedDocks) # populate dock self.dockWidgetContent = QtGui.QWidget() self.dockLayout = QtGui.QVBoxLayout(self.dockWidgetContent) # add dock into a layout hbox = QtGui.QHBoxLayout() hbox.addWidget(self.dock) # add the layout into my scroll area (ultraLayout is the general Layout inside my scroll) self.ultraLayout.insertLayout(-1, hbox) # set dock content self.dock.setWidget(self.dockWidgetContent)
Thank you !
Hi and welcome to devnet,
You should put your dock widgets in the available QMainWindow's dock area. Putting it in a layout like you do makes it treated as a normal widget.
Hi SGait !
I know that it might affect is behavior but the thing with the normal "dock area position" is that it doesn't do what I want.
If I switch tab, I will still have my docks visible as it is not part of the tab (in centralWidget) but part of the dockArea which is all around the centralWidget.
And further more, I m not even sure that by using the dockArea , I could have a scroll bar.
So, There is no way to make the out docked dockWidget movable ? except if I put it in a new widgetWindow (but I don't want to do that)?
If i have to go for the new widgetWindow, then I prefer not to use the QDockWidget anymore as it becomes useless and simply do layouts that will be parented under my scrollArea or a new widgetWindow.
You could have several QMainWindow in your stack as central widget if it's really what you need.
Out of curiosity, why do you need all these QDockWidget that changes for every tab ?
I only want my dock area to be in the first tab. That's all.
Then you can use a QMainWindow as widget in the first tab so you have everything you need in it and don't need to fiddle around to replicate the functionality