Note that there are some explanatory texts on larger screens.

plurals
  1. POsetGeometry() right after addWidget() issue
    primarykey
    data
    text
    <p>I'm having troubles setting dimensions of a child-QWidget right after it is added to a parent-QWidget. The issue is that it simply doesn't set the geometry:</p> <pre><code>from PyQt4 import QtCore, QtGui class MyWidget(QtGui.QWidget): def __init__(self): super(MyWidget, self).__init__() self.initUI() def initUI(self): # setting up parent QWidget self.setMinimumSize(256, 256) self.setMaximumSize(256, 256) self.GL = QtGui.QGridLayout(self) self.GL.setMargin(0) # setting up child QWidget self.GL.myWidget2 = QtGui.QFrame() self.GL.myWidget2.setMinimumSize(128, 128) self.GL.myWidget2.setMaximumSize(128, 128) self.GL.myWidget2.setStyleSheet("background: orange") # attaching child to parent self.GL.addWidget(self.GL.myWidget2) # trying to reposition child in parent's local space self.GL.myWidget2.setGeometry(QtCore.QRect(0, 128, self.width(), self.height())) if __name__ == '__main__': app = QtGui.QApplication(sys.argv) widget = MyWidget() widget.show() app.exec_() </code></pre> <p>Adding a timer that sets the geometry after a short delay does work though... (replacing <code>self.GL.myWidget2.setGeometry([...])</code> with):</p> <pre><code> timer = QtCore.QTimer() timer.singleShot(10, self.updatePosition) def updatePosition(self): self.GL.myWidget2.setGeometry(QtCore.QRect(0, 128, self.width(), self.height())) </code></pre> <p>...so I suspect the addWidget(...) method to be doing a callback e.g. that redraws the widget in its default position while the main thread has already passed the <code>self.GL.myWidget2.setGeometry([...])</code> line.</p> <p>This is purely speculative though, any inside into how <code>addWidget()</code> affects following coder or execution timing would be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload