[PyQt] Re: setLayout for a QDockWidget

TP paratribulations at free.fr
Mon Jun 29 09:09:50 BST 2009


Andreas Pakulat wrote:

> Thats not the way to use QDockWidget, please look at the dockwidgets
> example and the API documentation to find out how to use that properly.

The dockwidgets example uses setWidget. Why has QDockWidget a setLayout
class if we cannot use it? Qt documentation seems to say that there is
nothing wrong using setLayout.
I have re-written the example with setWidget (see below).

Thanks

####### first possibility
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class spinWidget( QWidget ):

    def __init__( self ):

        super( spinWidget, self ).__init__()
        vboxlayout = QVBoxLayout( )

        spin1 = QSpinBox()
        vboxlayout.addWidget( spin1 )

        spin2 = QSpinBox()
        vboxlayout.addWidget( spin2 )
        self.setLayout( vboxlayout )

app = QApplication( sys.argv )

qmainwin = QMainWindow()

qdock = QDockWidget( )
s = spinWidget()
qdock.setWidget( s )

qmainwin.addDockWidget( Qt.TopDockWidgetArea, qdock )
qmainwin.show()

app.exec_()

#### second possibility
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

app = QApplication( sys.argv )

qmainwin = QMainWindow()

s = QWidget()
vboxlayout = QVBoxLayout( )

spin1 = QSpinBox()
vboxlayout.addWidget( spin1 )

spin2 = QSpinBox()
vboxlayout.addWidget( spin2 )
s.setLayout( vboxlayout )

qdock = QDockWidget( )
qdock.setWidget( s )
qmainwin.addDockWidget( Qt.TopDockWidgetArea, qdock )
qmainwin.show()

app.exec_()




-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)



More information about the PyQt mailing list