demogorgon
demogorgon

Reputation: 484

QPushButton background-color overlaps border

I am using QPushButton class and adding the object to a QGraphicsProxyWidget after setting the style sheet. However, when I set a border-radius, the background-color still overlaps the border. How do I get rid of this?

Example: (where levelOneEasyProxy is QGrpahicsProxyWidget)

QPushButton* levelOneEasyButton = new QPushButton();
levelOneEasyButton->setGeometry(QRect(sceneRect().width()*0.05, sceneRect().height()*0.2, 70, 50));
levelOneEasyButton->setText("1");
levelOneEasyButton->setStyleSheet("QPushButton {"
                                  "background-color: rgb(92, 249, 158);"
                                  "color: white;"
                                  "font-size: 16px;"
                                  "border-style: solid;"
                                  "border-width: 2px;"
                                  "border-radius: 10px;"
                                  "}"
                                  "QPushButton:pressed {"
                                  "background-color: rgb(66, 191, 118);"
                                  "}");
levelOneEasyProxy = addWidget(levelOneEasyButton);
levelOneEasyProxy->setZValue(10.0);

Current Result:

enter image description here

Upvotes: 1

Views: 1360

Answers (1)

demogorgon
demogorgon

Reputation: 484

I discovered that using the code above will set the border-radius but the background needs to be set to translucent by using setAttribute on the QPushButton. This can be done with the following code:

qPushButtonObject->setAttribute(Qt::WA_TranslucentBackground);

This will get rid of the overlapping background-color.

Upvotes: 2

Related Questions