标签:exit .exe conf win box cstring odi config pos
临时消息在下一个操作触发时会自动消失;
self.statusBar().showMessage("this is status bar")
使用状态栏附加标签(或者其他Qwidget)的形式显示永久消息
self.label = QLabel("请打开项目 : [文件 -> 打开config.json]")
self.statusBar().addWidget(self.label)
self.setStyleSheet("QStatusBar{padding-left:8px;background:rgba(240,240,240,255);color:black;font-weight:bold;}")
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
QTextCodec.setCodecForCStrings(QTextCodec.codecForName("utf-8"))
重置内容
self.textBrowser.setText("this is new content")
添加内容
self.textBrowser.append("this is appended test")
清空内容
self.textBrowser.clear()
清空内容
self.comboBox.clear()
添加一条
self.comboBox.addItem("new Item")
添加列表
self.comboBox.addItems(list)
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui
from PyQt4.QtCore import pyqtSignature, QThread, QObject, pyqtSignal, QTextCodec,pyqtSignal
from PyQt4.QtGui import QFrame
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
QTextCodec.setCodecForCStrings(QTextCodec.codecForName("utf-8"))
class EmittingStream(QObject):
textWritten = pyqtSignal(str)
def write(self, text):
self.textWritten.emit(str(text))
class Example(QtGui.QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.setWindowTitle(u"测试")
self.textEdit = QtGui.QTextEdit(self)
self.textEdit.move(0,50)
self.textEdit.resize(350,300)
self.qbtn = QtGui.QPushButton(‘print‘, self)
self.qbtn.move(100, 10)
self.qbtn.clicked.connect(self.my_print)
self.setGeometry(300, 300, 350, 250)
self.setWindowTitle(‘Main window‘)
# 重定向输出
sys.stdout = EmittingStream(textWritten=self.normalOutputWritten)
sys.stderr = EmittingStream(textWritten=self.normalOutputWritten)
def my_print(self):
print("hello world!")
def normalOutputWritten(self, text):
# 重定向输出位置
cursor = self.textEdit.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertText(text)
self.textEdit.setTextCursor(cursor)
self.textEdit.ensureCursorVisible()
if __name__ == ‘__main__‘:
app = QtGui.QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
选择文件
my_file_path = QFileDialog.getOpenFileName(self, u‘选择config.json‘, ‘./‘, ‘*.json‘)
选择文件夹
dir_path = QFileDialog.getExistingDirectory(self, "choose exsiting directory", "./")
保存为文件
file_path = QFileDialog.getSaveFileName(self, "save file", "../","json(*.json);;all files(*.*)")
标签:exit .exe conf win box cstring odi config pos
原文地址:http://www.cnblogs.com/aloe-n/p/7979710.html