当对话框本身调整大小时,我很难自动调整QDialog中的小部件.
在以下程序中,如果您调整主窗口的大小,textarea会自动调整大小.但是,在调整对话框大小时,对话框中的textarea保持相同的大小.
有没有办法让对话框中的textarea自动调整大小?我已尝试在对话框本身和内部的两个小部件上使用setSizePolicy(QSizePolicy.Ignored,QSizePolicy.Ignored),但这似乎没有任何效果.
我在openSuSE 10.2上使用Qt版本3.3.7和PyQt版本3.5.5-29,如果这是相关的.
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()