Hi,

I tried that, but is does not seem to work. The 'XXX' is still hidden by the widget in the layout.

What I eventually would like to achieve is to add a QPushButton in, say, the upper left corner of the parent widget.

I have attached a similar example, this time with a QPushButton. This QPushButton is rendered useless (i.e.) you cannot press it.

I thought solving this problem would be a walk in the park. Any clues?

Best regards,

Mads


On 2011-04-07 15:19, Hans-Peter Jansen wrote:
On Thursday 07 April 2011, 14:58:30 Mads Ipsen wrote:
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.
Create _label2 after _label1, but this is a questionable approach.

Why can't you use something like QStackedLayout?

Pete
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

--
+-----------------------------------------------------+
| Mads Ipsen                                          |
+----------------------+------------------------------+
| Florsgade 7, 4. th   |                              |
| DK-2200 København N  | phone:          +45-29716388 |
| Denmark              | email:  mads.ip...@gmail.com |
+----------------------+------------------------------+


import sys

from PyQt4 import QtGui

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

        self._label  = QtGui.QLabel('A Label')
        self._button = QtGui.QPushButton('&Push Me', self)

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

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

        x = (self.rect().width()  - w)/2.0
        y = (self.rect().height() - h)/2.0
        self._button.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