0
在PyQt4,有没有办法暂停调整窗口的大小,直到一个函数完成?PyQt如何执行功能之前的GUI调整大小事件
我的问题是,我创建了一个文本编辑窗口,可能包含大量的文本。由于我切换到使用网格布局,因此文本编辑也会被调整大小,并且当有很多文本时,应用程序会挂起。我尝试覆盖resizeEvent以在调整大小时清除文本编辑文本,但应用程序仍然挂起,因为它仅在调整大小后才清除文本。
其他解决方案也欢迎。
的Python代码(和所述的.ui文件的链接):
import sys
from PyQt4 import QtGui, uic, QtCore
from PyQt4.QtGui import QDesktopWidget
qtCreatorMainWindowFile = "mainwindow.ui"
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorMainWindowFile)
class MainWindow(QtBaseClass, Ui_MainWindow):
def __init__(self):
QtBaseClass.__init__(self)
self.setupUi(self)
# Set window size to 4/5 of the screen dimensions
sg = QDesktopWidget().screenGeometry()
self.resize(sg.width()*4/5, sg.height()*4/5)
self.clearTextBrowserButton.clicked.connect(self.ClearTextBrowsers)
@staticmethod
def WriteToTextBrowser(string, text_browser):
cursor = text_browser.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertText(string)
text_browser.setTextCursor(cursor)
text_browser.ensureCursorVisible()
def ClearTextBrowsers(self):
self.textBrowser.clear()
# def resizeEvent(self,event):
# print "resize"
# self.ClearTextBrowsers()
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
for i in range(1,100000):
window.WriteToTextBrowser("TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTEST\r\n",window.textBrowser)
sys.exit(app.exec_())
的用户界面。文件: https://www.dropbox.com/s/y3hxp6mjhfpv2hy/mainwindow.ui?dl=0
一种选择可能是为了避免调整窗口的大小? – eyllanesc
不幸的是,这是切换到网格布局的关键。 – sas
@sas如果您找到解决方案,我建议您将其发布为答案。 – eyllanesc