文档介绍:QT 中设置字体和更改字体颜色更改部分: setTextColor ( QColor ( "red" )) 更改全部: 对一个文本框 lineEdit 设置字体,首先我建了一个按钮 setFontButton 用来设置并定义了它的相应函数 setFont ,将 setFontButton 添加到布局中,并通过 connect ()设置与 setFont() 关联, 然后定义 setFont 如下 void FindDialog::setFont() { bool ok; const QFont& font = QFontDialog::getFont(&ok, lineEdit->font(), this, tr("fontDialog")); if(ok) { lineEdit->setFont(font); }} 这样就可以设置字体了改变字体或按钮的颜色: 先加入色板类#include <Qpalette> 比如要设置 lineEdit 里字体的颜色为红色 QPalette pal =lineEdit->QPalette(); pal->setColor(QPalette::Text,QColor(255,0,0); lintEdit->setPalette(pal); 这样文本框中的字体就变成红色的了。如果要通过调用色板来选择字体颜色,可以加上下列代码,其中的按钮创建,连接等省略 void FindDialog::setFont { QPalette palette = lineEdit->palette(); const QColor & color = QColorDialog::getColor((QPalette::Base),this); if(()) { (QPalette::Text,color); lineEdit->setPalette(palette); }} Qt 中控件的字体颜色设置一般的属于 QWidget 子类的一些控件,可以直接使用样式表,例如 label->setStyleSheet("color:white"); 其他的一些不属于 QWidget 子类的控件,可以考虑设置其前景色,例如各种 View treeWidgetItem->setForeground(0,QBrush(QColor(Qt::white))); QT 中设置字体和更改字体颜色 2010-08-12 14:54:08| 分类: linux 编程|标签: 字体 lineedit qpalette setfont palette |字号大中小订阅对一个文本框 lineEdit 设置字体,首先我建了一个按钮 setFontButton 用来设置并定义了它的相应函数 setFont ,将 setFontButton 添加到布局中,并通过 connect ()设置与 setFont() 关联, 然后定义 setFont 如下[code] void FindDialog::setFont() { bool ok; const QFont& font = QFontDialog::getFont(&ok, lineEdit->font(), this, tr("fontD