更改QLCD号码的数字颜色 [英] Changing the Digit Color of QLCD Number
问题描述
我想在 Qt Designer 中更改 QLCDNumber
的背景和数字颜色,我将在我的 Python 程序中使用该设计(GUI).
有人说,这可以让我在 Qt-Designer 中添加样式表.
QLCDNumber{color:rgb(85, 85, 255);background-color:rgb(0, 170, 255);}
背景颜色成功,数字颜色成功.
如何尝试获取数字颜色
谢谢
<小时>我不能使用最后两个 setColor(用于浅色边框和深色边框).我正在使用 pyuic4 工具从 Qt4 Designer 生成 python 代码(用于 GUI).我将代码添加到我的 python 代码文件中(以 .py 而不是 .ui 结尾),如下所示
self.palette = self.withpalette.palette()self.palette.setColor(QtGui.Palette.WindowText,QtGui.QColor(85,85,255))self.palette.setColor(QtGui.Palette.Background,QtGui.QColor(0,170,255))self.palette.setColor(QtGui.Palette.Light,QtGui.QColor(255,0,0))self.palette.setColor(QtGui.Palette.Dark,QtGui.QColor(0,255,0))self.withpalette.setPalette(self.palette)
实际上,它有效.QLCDNumber
,默认情况下,以凸起"样式绘制数字.对于小尺寸,这些具有凸起效果的边框将主要覆盖数字,您将看不到正常颜色.如果你把它放大,它会显示:
如果您不想要这种凸起"效果,可以使用 .QPalette.Light
和 QPalette.Dark
是控制这些边框的两种颜色.
#获取调色板调色板 = lcd.palette()# 前景色Palette.setColor(palette.WindowText, QtGui.QColor(85, 85, 255))# 背景颜色Palette.setColor(palette.Background, QtGui.QColor(0, 170, 255))# 轻"边框Palette.setColor(palette.Light, QtGui.QColor(255, 0, 0))# 深色"边框Palette.setColor(palette.Dark, QtGui.QColor(0, 255, 0))# 设置调色板lcd.setPalette(调色板)
I want to change the background and digit color of QLCDNumber
in Qt Designer and I am going to use that design(GUI) on my Python program.
Some people said, that can get my adding style sheet in Qt-Designer.
QLCDNumber{color:rgb(85, 85, 255);background-color:rgb(0, 170, 255);}
It is successful for background color not for digit color.
How do I try for getting digit color
Thanks
I can't used the last two setColor(for light border and dark border). I was generating the python code(for GUI) from Qt4 Designer with pyuic4 tool. I added the codes into my python code file (ending with .py not .ui) as follows
self.palette = self.withpalette.palette()
self.palette.setColor(QtGui.Palette.WindowText,QtGui.QColor(85,85,255))
self.palette.setColor(QtGui.Palette.Background,QtGui.QColor(0,170,255))
self.palette.setColor(QtGui.Palette.Light,QtGui.QColor(255,0,0))
self.palette.setColor(QtGui.Palette.Dark,QtGui.QColor(0,255,0))
self.withpalette.setPalette(self.palette)
Actually, it works. QLCDNumber
, by default, paints digits in "raised" style. For small sizes, these borders that give the raised effect will mostly cover the digit and you won't see the normal color. If you make it larger, it will show:
If you don't want this "raised" effect, you can turn it off with setSegmentStyle
:
lcd.setSegmentStyle(QtGui.QLCDNumber.Flat)
On the other hand, if you want the "raised" effect but want to control it, you need to do it via QPalette
. QPalette.Light
and QPalette.Dark
are the two colors that control those borders.
# get the palette
palette = lcd.palette()
# foreground color
palette.setColor(palette.WindowText, QtGui.QColor(85, 85, 255))
# background color
palette.setColor(palette.Background, QtGui.QColor(0, 170, 255))
# "light" border
palette.setColor(palette.Light, QtGui.QColor(255, 0, 0))
# "dark" border
palette.setColor(palette.Dark, QtGui.QColor(0, 255, 0))
# set the palette
lcd.setPalette(palette)
这篇关于更改QLCD号码的数字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!