Darko
Darko

Reputation: 609

Layout management on PyQt4 Docks

I am a total GUI n00b developing an application in PyQt4. The application is designed for a lab bench, in which it will first search for equipment, and then populate the main window with docked windows, one for each piece of equipment it finds. The interface for each piece of equipment will each look different, with an assortment of widgets for controlling and monitoring that particular piece of equipment.

My question is, how do I add a layout to a dock? Generally speaking, my instrument panels are QtGui.QGridLayout() with an assortment of widgets that build it up. However, when I attempt to set the layout of a new dock, I get an error:

 oscilloscopeGrid = QtGui.QGridLayout()

 ...add widgets too grid build up interface for oscilloscope

 oscilloscopeDock = QtGui.QDockWidget("MSO-X-3034A", self)
 oscilloscopeDock.setLayout(oscilloscopeGrid)

The code runs, but my instrument control panel design does not show up on the dock and I get the following warning on the console:

 QWidget::setLayout: Attempting to set QLayout "" on QDockWidget "", which
 already has a layout

Upvotes: 0

Views: 397

Answers (1)

user1092803
user1092803

Reputation: 3297

QDockWidget already has a layout (as the error say)

You should try something like this (pseudocode)

grid = QWidget()
layout = QGridLayout()
... add the widget to the layout
grid.setLayout(layout)
dock = QDockWidget()
dock.setWidget(grid)

Upvotes: 1

Related Questions