Note that there are some explanatory texts on larger screens.

plurals
  1. POPyQt: getting widgets to resize automatically in a QDialog
    text
    copied!<p>I'm having difficulty getting widgets in a QDialog resized automatically when the dialog itself is resized.</p> <p>In the following program, the textarea resizes automatically if you resize the main window. However, the textarea within the dialog stays the same size when the dialog is resized.</p> <p>Is there any way of making the textarea in the dialog resize automatically? I've tried using <code>setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)</code> on the dialog itself and the two widgets within, but that seems to have no effect.</p> <p>I'm using Qt version 3.3.7 and PyQt version 3.5.5-29 on openSuSE 10.2, if that's relevant.</p> <pre><code>import sys from qt import * # The numbers 1 to 1000 as a string. NUMBERS = ("%d " * 1000) % (tuple(range(1,1001))) # Add a textarea containing the numbers 1 to 1000 to the given # QWidget. def addTextArea(parent, size): textbox = QTextEdit(parent) textbox.setReadOnly(True) textbox.setMinimumSize(QSize(size, size*0.75)) textbox.setText(NUMBERS) class TestDialog(QDialog): def __init__(self,parent=None): QDialog.__init__(self,parent) self.setCaption("Dialog") everything = QVBox(self) addTextArea(everything, 400) everything.resize(everything.sizeHint()) class TestMainWindow(QMainWindow): def __init__(self,parent=None): QMainWindow.__init__(self,parent) self.setCaption("Main Window") everything = QVBox(self) addTextArea(everything, 800) button = QPushButton("Open dialog", everything) self.connect(button, SIGNAL('clicked()'), self.openDialog) self.setCentralWidget(everything) self.resize(self.sizeHint()) self.dialog = TestDialog(self) def openDialog(self): self.dialog.show() if __name__ == '__main__': app = QApplication(sys.argv) mainwin = TestMainWindow(None) app.setMainWidget(mainwin) mainwin.show() app.exec_loop() </code></pre>
 

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