Hi,

I have attached a simple example where a widget sets up two labels. One which is added to the layout of the widget, and one which is not.

In the paintEvent() of the parent widget I instead position the non-layout label using setGeometry to make it appear in the center of the parent widget.

However, the label positioned by this approach is always obscured by the widget which was added to the layout. I want it to appear as visible, i.e. visible on top of the parent widget.

Any clues?

Best regards,

Mads
import sys

from PyQt4 import QtGui

class Widget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self)

        self._label2 = QtGui.QLabel('XXX', self)
        self._label2.show()
        self._label1 = QtGui.QLabel()

        self._label1.setAutoFillBackground(True)
        palette = QtGui.QPalette()
        palette.setColor(self._label1.backgroundRole(), QtGui.QColor('blue'))
        self._label1.setPalette(palette)

        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)
        layout.addWidget(self._label1)

    def paintEvent(self, event):
        w = self._label2.width()
        h = self._label2.height()

        x = (self.rect().width()  - w)/2.0
        y = (self.rect().height() - h)/2.0
        self._label2.setGeometry(x,y,w,h)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)

    widget = Widget()
    widget.show()

    sys.exit(app.exec_())
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to