[PyQt] Adding a layout to a QSlider widget

"V. Armando Solé" sole at esrf.fr
Wed Jun 23 11:33:09 BST 2010


Hello,

I am trying to create a widget consisting on a horizontal QSlider and an 
additional widget at its side. The widget should behave as a QSlider.

I have tried to do it inheriting from a QSlider but the problem is I 
cannot get the additional widget at the side of the slider. It stays on top.

It can be observed with the example below. 

Why the added layout overwrites the QSlider?

Is there something I am missing or I have to implement everything 
starting from a QAbstractSlider?

Thanks for your time.

Best regards,

Armando

from PyQt4 import QtCore, QtGui

class SliderWithBrowser(QtGui.QSlider):
    def __init__(self, *var, **kw):
        QtGui.QSlider.__init__(self, *var, **kw)
        self.setOrientation(QtCore.Qt.Horizontal)
        self.mainLayout = QtGui.QHBoxLayout(self)
        self.mainLayout.setMargin(0)
        self.mainLayout.setSpacing(2)
        self.label = QtGui.QLabel(self)
        self.label.setText("This should not be on top of the Slider")
        self.mainLayout.addWidget(self.label)
        
def test(args):
    app=QtGui.QApplication(args)
    w=SliderWithBrowser()
    w.show()
    app.exec_()
                                   
if __name__=="__main__":
    import sys
    test(sys.argv)




More information about the PyQt mailing list