C++ 按下QPushButton背景色
如何获得QPushButton的按下背景色C++ 按下QPushButton背景色,c++,qt,qcolor,qpalette,C++,Qt,Qcolor,Qpalette,如何获得QPushButton的按下背景色 if (isDown()) _BGColor = <pressed background color>; // how to get this??? else _BGColor = palette().color(QPalette::Background); // this is to get the idle backcolor if(isDown()) _BGColor=;//如何得到这个??? 其他的 _BGColo
if (isDown())
_BGColor = <pressed background color>; // how to get this???
else
_BGColor = palette().color(QPalette::Background); // this is to get the idle backcolor
if(isDown())
_BGColor=;//如何得到这个???
其他的
_BGColor=palete().color(qpalete::Background);//这是为了得到空闲的背景色
提前感谢 很难(如果不是不可能的话)找到一种方法来获取按钮按下时的背景颜色,因为它取决于样式,并且不能保证样式尊重调色板
然而,我建议两种不同的方法:
painter.setPen(QColor(255, 255, 255));
painter.setCompositionMode(QPainter::RasterOp_SourceAndNotDestination);
(请注意,使用此示例时,中灰色(128、128、128)的反向颜色完全相同)
请参见欢迎来到Stackoverflow。你能解释一下你想做什么吗?看来换成这种颜色不是个好主意。也许我们可以找到更好的解决你的初始问题的方法?我有一个QPushButton子类,当按钮长按时,我想画一个背景颜色相反的圆圈,然后在里面是背景颜色的复选符号。我的另一个选择是擦除圆圈的一部分(使部分透明)来创建一个复选标记。我要做的是在我的按钮上加上一个覆盖圆,中间有一个支票形状的整体。它用于按钮的checked属性,比如有一个复选框,但我想将其呈现为绘图。您是否在子类的PaintEvent中编写了上述代码,尝试在PaintEvent中编写它并在mousePressEvent中调用Update函数。这将为您提供背景色的当前值。我已尝试使用
update()
和/或repaint()
高于setDown(true)
,但它没有获得背景色的当前值。