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. 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.

Here is a picture:

My code:

QColor color = QColorDialog::getColor(m_couleur);
if (color.isValid()) m_couleur=color;

Basically I would like the QToolButton to look something like this:

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);

No CSS involved in this case is (for me ofcourse) big pro

Use the setStylesheet function in order to change the background color of your button

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. 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()));

Need Your Help

Why is this not a bug in qmail?

c unix qmail

I was reading DJB's "Some thoughts on security after ten years of Qmail 1.0" and he listed this function for moving a file descriptor:

PIC18F SPI slave interrupt receiving multiple bytes at 4 MHz issue

pic interrupt-handling spi 8bit

I am writing code to receive SPI data in an interrupt service routine on a PIC18F2680 microcontroller that is running at 40MHz that needs to receive 2 bytes (16 bits) of data from another microcont...