UDPATE: I may have realized that QDockWidget isn't the way to go. I have posted a new question here: PyQt: Is it possible to drag/drop QWidgets in a QGridLayout to rearrange them?
Original question:
I am trying to make a scrollable area containing two columns of several dockable widgets. Furthermore, I would like the scrollable dock area to be placed to the right in a QHBoxLayout. Right now I have a single column of QDockWidgets with no scrolling, and a QTextEdit as my central widget.
I would like help to integrate the following:
- Add the possibility for another column of QDockWidgets
- Disable the function to undock to a new window. I would still like to rearrange the docks
- Add the scrollarea and scrollbar to the dockarea
- I would like the layout to be a QHBoxLayout with the dockarea to the right.
The image illustrates what I have and what I want. Hope you can help!
from PyQt5 import QtCore, QtWidgets, QtGui
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import random
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.textEdit = QtWidgets.QTextEdit()
self.setCentralWidget(self.textEdit)
# First dock
dock1 = QtWidgets.QDockWidget("dock 1", self)
dock1.setAllowedAreas(QtCore.Qt.RightDockWidgetArea)
dock1.setFloating(False)
self.figure1 = Figure() # a figure to plot on
self.canvas1 = FigureCanvas(self.figure1)
self.ax1 = self.figure1.add_subplot(111) # create an axis
data = [random.random() for i in range(10)]
self.ax1.plot(data, '*-') # plot data
self.canvas1.draw() # refresh canvas
dock1.setWidget(self.canvas1)
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock1)
# Second dock
dock2 = QtWidgets.QDockWidget("dock 2", self)
dock2.setAllowedAreas(QtCore.Qt.RightDockWidgetArea)
self.figure2 = Figure() # a figure to plot on
self.canvas2 = FigureCanvas(self.figure2)
self.ax2 = self.figure2.add_subplot(111) # create an axis
data = [random.random() for i in range(10)]
self.ax2.plot(data, '*-') # plot data
self.canvas2.draw() # refresh canvas
dock2.setWidget(self.canvas2)
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock2)
# import dockwidgets_rc
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())