Note that there are some explanatory texts on larger screens.

plurals
  1. POresizing a dialog with PyQt4
    primarykey
    data
    text
    <p>I have this sample of code:</p> <pre><code>import sys from PyQt4.QtGui import (QApplication, QHBoxLayout, QVBoxLayout, QDialog, QFrame, QPushButton, QComboBox) class Form(QDialog): def __init__(self, parent=None): super(Form, self).__init__(parent) moreButton = QPushButton('moreButton') moreButton.setCheckable(True) resizeButton = QPushButton('Resize') combo = QComboBox() combo.addItems(['item1', 'item2']) layout1 = QHBoxLayout() layout1.addWidget(moreButton) layout1.addWidget(resizeButton) layout2 = QHBoxLayout() layout2.addWidget(combo) self.frame = QFrame() self.frame.setLayout(layout2) self.frame.hide() layout3 = QVBoxLayout() layout3.addLayout(layout1) layout3.addWidget(self.frame) moreButton.toggled.connect(self.frame.setVisible) moreButton.clicked.connect(self.method) resizeButton.clicked.connect(self.method) self.setLayout(layout3) self.resize(630, 50) def method(self): if self.frame.isVisible(): self.resize(630, 150) else: self.resize(630, 250) app = QApplication(sys.argv) form = Form() form.show() app.exec_() </code></pre> <p>I run it and when moreButton clicked the ComboBox appears or disappears. Dialog's size also changes. But if I change the method to:</p> <pre><code>def method(self): if self.frame.isVisible(): self.resize(630, 150) else: self.resize(630, 50) </code></pre> <p>(in order to set the initial size when combo is hidden) the resizing does not work. However, if I click resizeButton -which is connected to the same method- the resizing works properly. </p> <p>I know that there are other ways to achieve such a result (eg. layout.setSizeConstraint(QLayout.SetFixedSize)), but I want to declare size explicitly. </p> <p>What am I doing wrong?</p>
    singulars
    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