Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you remove the border from a QPushButton?

Tags:

qt

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

Example of borders

like image 212
spencewah Avatar asked Sep 20 '11 20:09

spencewah


2 Answers

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

like image 67
RajaRaviVarma Avatar answered Oct 28 '22 14:10

RajaRaviVarma


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

like image 9
Nicholas Smith Avatar answered Oct 28 '22 14:10

Nicholas Smith