Reputation: 2236
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 stylesheets, as I like the automatic color generation provided by QPalette's constructor
Upvotes: 8
Views: 30228
Reputation: 357
button.setStyleSheet("QPushButton { border: none; }")
As said @RajaRaviVarma
Upvotes: 0
Reputation: 362
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.
Upvotes: 0
Reputation: 2742
If you are using Qt creator, right click the QPushButton and setStyleSheet as border: none;
Thats it.
Upvotes: 22
Reputation: 11754
If you set the QButton property isFlat = true it should disable the border unless it's being clicked.
Upvotes: 10