lea*_*ode 5 python qstring pyqt4 qlineedit
如何更改QLineEdit的颜色和字体?
这是我的代码:
self.lineEdit = QtGui.QLineEdit(widget)
self.lineEdit.setText("enter keywords here") #I want this to be in italics and in brown color
Run Code Online (Sandbox Code Playgroud)
文档中的setText那一行说里面的文本是QString,如何更改它的字体和颜色?
对于 Color 使用QPallete,然后使用{your palette}.setColor(QtGui.QPalette.Text, {your QColor}),并且字体使用QFont
我的解决方案:
from PyQt4 import QtGui
from PyQt4 import QtCore
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
w = QtGui.QLineEdit()
palette = QtGui.QPalette()
palette.setColor(QtGui.QPalette.Text, QtCore.Qt.red)
w.setPalette(palette)
font = QtGui.QFont("Times", 15, QtGui.QFont.Bold)
w.setFont(font)
w.show()
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8069 次 |
| 最近记录: |