设定值:
- 大段文本
self.textEdit.setPlainText(text)
- 静态label
self.lbl.setText("PyQt4")
- 设定静态label初始值
self.lbl.setText("hello"+self.singlelineEdit.text())
- 字体
self.label.setFont(font)
- 修改颜色
self.label.setStyleSheet("QWidget { background-color: %s }" % color.name())
获取值:
- 单行输入框
self.singlelineEdit.text()
- 单选radiobox,单选按钮本来就没有value的
self.radiobutton.isCheck()
- 滑动取值spinbox
self.spinbox.value()
- 获得日期值
thedate=self.calendarWidget.selectedDate()
- 日期值转化为string
thedatestring=str(thedate.toPyDate())
- 下拉列表combobox值的初始化
def __init__(self, parent = None):
self.typelist=['first', 'second', 'third']
self.addcommobox()
def addcommobox(self):
for i in self.typelist:
self.typecomboBox.addItem(i)
- 下拉列表combobox值
self.typecomboBox.currentText()
- 下拉列表combobox的index
self.typecomboBox.currentIndex()
其他功能:
____________
打开文件:
def on_openfile_clicked(self):
dlg = PyQt4.QtGui.QFileDialog(self)
self.filename = dlg.getOpenFileName()
from os.path import isfile
if isfile(self.filename):
import codecs
text = codecs.open(self.filename,'r','cp936').read()
self.textEdit.setPlainText(text)