【发布时间】:2017-09-16 14:29:11
【问题描述】:
在 PyQt4 中,有没有办法在某个函数完成之前暂停调整窗口大小?
我的问题是我创建了一个带有文本编辑的窗口,其中可能包含大量文本。由于我切换到使用网格布局,文本编辑也会调整大小,当有很多文本时,应用程序会挂起。我尝试覆盖 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
【问题讨论】:
-
一个选项可能是避免调整窗口大小?
-
很遗憾,这就是切换到网格布局的全部意义所在。
标签: python python-2.7 pyqt pyqt4 qgridlayout