spencewah
spencewah

Reputation: 2236

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 stylesheets, as I like the automatic color generation provided by QPalette's constructor

Example of borders

Upvotes: 8

Views: 30228

Answers (4)

tCot
tCot

Reputation: 357

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

As said @RajaRaviVarma

Upvotes: 0

Mykola Tetiuk
Mykola Tetiuk

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

RajaRaviVarma
RajaRaviVarma

Reputation: 2742

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

Upvotes: 22

Nicholas Smith
Nicholas Smith

Reputation: 11754

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

Upvotes: 10

Related Questions