Search code examples
c++qtqtstylesheetsqpushbutton

Set transparency of QButtons in QT C++ in Linux


I am using Qt Creator 4.0.2 Based on Qt 5.7.0 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64 bit).

I am displaying an image on my widget and placing QButtons and QLabels on top of it.

It looks something like this:

Window with image and button

I want to make the button semi-transparent. There isn't any property for it. I tried the answer given on another thread as:

ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 50);");

But it didn't work for me. I also tried setStyleSheet("background:transparent;") But it didn't work.

Please suggest a way of doing it.


Solution

  • setting the bg color to "transparent" is not enough, you need to set the "border-style: outset;" and nothing else in the main window/widget...

    ui->pushButton_7->setStyleSheet("background-color: transparent; style: outset;");
    

    enter image description here

    then:

    do:

    ui->pushButton_7->setStyleSheet("background-color: #FF0011");
    auto qgoEffect = new QGraphicsOpacityEffect(this);
    qgoEffect->setOpacity(0.15);
    ui->pushButton_7->setGraphicsEffect(qgoEffect);
    ui->pushButton_7->setAutoFillBackground(true);
    

    enter image description here