[英]How to get the application font color in Qt
I want to put some text on my UI. 我想在我的UI上放一些文字。
I am drawing the text in a paint event of a widget using painter. 我正在使用画家在小部件的绘制事件中绘制文本。
Here is the sample code, which shows how I am drawing the text: 以下是示例代码,其中显示了我如何绘制文本:
QWidget::paintEvent(painter);
QPainter paint(this);
paint.drawText(QPoint(10,30),"Duplex");
However, the text color looks like the default theme color. 但是,文本颜色看起来像默认主题颜色。 How do I set the application font color to the text in a paint event?
如何在paint事件中将应用程序字体颜色设置为文本?
here is the answer i got it 这是我得到它的答案
QPen pen = (QApplication::palette().text().color());
paint.setPen(pen);
You have to use the QPainter::setBrush(QBrush &)
and QPainter::setPen(QPen &)
methods to change the color used to draw graphics (and incidently the text color). 您必须使用
QPainter::setBrush(QBrush &)
和QPainter::setPen(QPen &)
方法来更改用于绘制图形的颜色(以及QPainter::setPen(QPen &)
的文本颜色)。
The command paint.setPen(QPen(QColor(255,0,0))
will set the outline color to red and paint.setBrush(QBrush(QColor(0,255,0))
will set the fill color to green. 命令
paint.setPen(QPen(QColor(255,0,0))
将轮廓颜色设置为红色, paint.setBrush(QBrush(QColor(0,255,0))
将填充颜色设置为绿色。
You can also use directly the QPainter::setPen(QColor &)
methods to change the color of the outline. 您也可以直接使用
QPainter::setPen(QColor &)
方法来更改轮廓的颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.