开发者

How do you remove the border from a QPushButton?

I have some QPushButtons in the rows of a QTreeView, and they're showing up with these black borders around them that I can't seem to modify. Currently I can grey out the buttons with this code:

for (int i = 0; i < QPalette::NColorRoles; i++){
    QPalette::ColorRole thisRole = static_cast<QPalette::ColorRole>(i);
    QColor newColor = commitPalette.color(QPalette::Disabled,thisRole);
    int grayColor = qGray(newColor.rgb());
    newColor.setRgb(grayColor,grayColor,grayColor,50);
    commitPalette.setColor(QPalette::Disabled, thisRole, newColor);
}

But it doesn't do anything to the border. I'd prefer to avoid using styleshe开发者_高级运维ets, as I like the automatic color generation provided by QPalette's constructor

How do you remove the border from a QPushButton?


If you are using Qt creator, right click the QPushButton and setStyleSheet as border: none; Thats it.


If you set the QButton property isFlat = true it should disable the border unless it's being clicked.


I suggest using a stylesheet. From the code you can make it to a function:

void setFlatStyle(QPushButton *btn)
{
    btn->setStyleSheet(QString("QPushButton {border: 0px;}"));
}

Just pass the button in there and get your result.


button.setStyleSheet("QPushButton { border: none; }")

As said @RajaRaviVarma

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜