2016-12-29 96 views
2

QLineEditの色とフォントはどのように変更できますか?ここでQStringまたはQLineEditの色とフォントを変更する

が私のコードです:

self.lineEdit = QtGui.QLineEdit(widget) 
self.lineEdit.setText("enter keywords here") #I want this to be in italics and in brown color 

DocumentationからsetTextラインは、内のテキストは、私はそれは、フォントや色です変更することができる方法のQStringであると言いますか?

答えて

2

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_()) 

enter image description here

+1

@learncode QLineEditはQWidgetの子であるため、親メソッドを持ちます。 – eyllanesc

+1

@learncode私はQ​​t Widgetのドキュメントを使用しています。継承されたメンバーを含むすべてのメンバーのリストを見ています:http://doc.qt.io/qt-5/qlineedit-members.html – eyllanesc

1

あなたがして色を変更することができます。

self.lineEdit.setStyleSheet("color: rgb(x,x,x)") 

フォントサイズ:色の

self.lineEdit.setStyleSheet("fontName='Times-Italic'") 
+0

ありがとう!私は色を変更することができますが、フォントを変更することはできませんか? – learncode

関連する問題