[英]QToolButton and color
I'm trying to make a simple design to select a color and I'm using a QToolButton to open a QColorDialog. 我试图做一个简单的设计来选择一种颜色,并且我正在使用QToolButton打开QColorDialog。 My problem is that I would like the QToolButton to be of the selected color but I've only suceeded to set the background color, which is not what I want.
我的问题是我希望QToolButton处于选定的颜色,但是我只能设置背景颜色,这不是我想要的。
Here is a picture: 这是一张图片:
My code: 我的代码:
QColor color = QColorDialog::getColor(m_couleur);
if (color.isValid()) m_couleur=color;
m_labelCouleur->setPalette(QPalette(m_couleur));
m_labelCouleur->setAutoFillBackground(true);
m_buttonCouleur->setPalette(QPalette(m_couleur));
m_buttonCouleur->setAutoFillBackground(true);
Basically I would like the QToolButton to look something like this: 基本上,我希望QToolButton看起来像这样:
edit: Can anyone explain to me why the website won't let me add "Hi everybody" at the beginning? 编辑:谁能向我解释为什么该网站不允许我在开头添加“大家好”?
QColor color = QColorDialog::getColor(m_couleur);
QPixmap px(20, 20);
px.fill(color);
m_buttonCouleur->setIcon(px);
No CSS involved in this case is (for me ofcourse) big pro (当然,对我而言)这种情况下涉及的CSS并不是大问题
使用setStylesheet
函数以更改按钮的背景色
m_buttonCouleur->setStyleSheet(QString("QToolButton{ background: %1; }").arg(m_couleur.name()));
I've done exactly that by using a QPushButton and setting its style sheet to the result from the color picker. 通过使用QPushButton并将其样式表设置为颜色选择器的结果,我已经做到了。 I guess a tool button should probably be the same.
我猜一个工具按钮可能应该是相同的。
button->setStyleSheet(QString("background-color: %1; "
"border: 1px; "
"border-color: black; "
"border-style: outset;").arg(color.name()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.