更新由qt designer连续构建的GUI值

时间:2014-02-13 08:40:47

标签: python ubuntu qt-designer

我在ubuntu系统中使用qt4。 我有一个需要在GUI中查看的文本文件。但问题是我的文本文件会不断自动更新。当文本文件更新时,如何更新GUI中的值。

这是我的计划:

#!/usr/bin/python
import os,getpass
import sys
import time
from subprocess import call
import subprocess
userName=getpass.getuser()
from PyQt4 import QtCore, QtGui

try:
  _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
  _fromUtf8 = lambda s: s

class Ui_MainWindow(object):
  def setupUi(self, MainWindow):
    MainWindow.setObjectName(_fromUtf8("MainWindow"))
    MainWindow.resize(455, 317)
    self.centralwidget = QtGui.QWidget(MainWindow)
    self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
    self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
    self.textBrowser.setGeometry(QtCore.QRect(10, 80, 431, 141))
    self.textBrowser.setSource(QtCore.QUrl(_fromUtf8("file:///home/"+userName+"/updated.txt")))
    self.textBrowser.setObjectName(_fromUtf8("textBrowser"))
    self.label = QtGui.QLabel(self.centralwidget)
    self.label.setGeometry(QtCore.QRect(20, 20, 621, 71))
    font = QtGui.QFont()
    font.setPointSize(24)
    font.setBold(True)
    font.setItalic(True)
    font.setWeight(75)
    self.label.setFont(font)
    self.label.setObjectName(_fromUtf8("label"))
    MainWindow.setCentralWidget(self.centralwidget)
    self.menubar = QtGui.QMenuBar(MainWindow)
    self.menubar.setGeometry(QtCore.QRect(0, 0, 455, 25))
    self.menubar.setObjectName(_fromUtf8("menubar"))
    MainWindow.setMenuBar(self.menubar)
    self.statusbar = QtGui.QStatusBar(MainWindow)
    self.statusbar.setObjectName(_fromUtf8("statusbar"))
    MainWindow.setStatusBar(self.statusbar)

    self.retranslateUi(MainWindow)
    QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
    MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
    self.label.setText(QtGui.QApplication.translate("MainWindow", "Some Program", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
  import sys
  app = QtGui.QApplication(sys.argv)
  MainWindow = QtGui.QMainWindow()
  ui = Ui_MainWindow()
  ui.setupUi(MainWindow)
  MainWindow.show()
  sys.exit(app.exec_())

0 个答案:

没有答案