简体   繁体   中英

How to set opacity in QT brush

How can i set the background color with an opacity when using QT Creator and C++.

In this case I want the QT::yellow and QT::Green to both have an opacity of 70%.

    if (isSelected()) {
        painter->setPen(QPen(Qt::darkYellow));
        painter->setBrush(Qt::yellow);
    } else {
        painter->setPen(QPen(Qt::darkGreen));
        painter->setBrush(Qt::green);
    }

You need to set the alpha channel on the color.

QColor green70 = Qt::green;
green70.setAlphaF( 0.7 );
painter->setBrush( green70 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM