QString button_style ="QPushButton{border-radius: 5px;background:red;border: 1px groove gray;border-style: outset}“ ; //
border-radius表示贺角半径的半径大小(像素)QPushButton* btn = new QPushButton("ddd",this);
btn->setStyleSheet(button_style);
background可以设置其背景色,
另一种设置背景色的方法是使用调色板:
QPalette palette;
palette.setBrush(QPalette::Button,QBrush(Qt::red));
btn->setPalette(palette);
btn->setAutoFillBackground(true); //这句不能少,否则不能刷满整个控件。
如果有特殊需要,可有通过重载QWidget来自定义所需要的控件样式。
依据两种不同的需求可以有两种不同的处理方式。
1)如果涉及到填充的背景颜色,且不是不断变换的,需要重载paint()函数;
2)如果涉及到的颜色固定,则可以考虑用stylesheet;
3)对于边框,可以在paint()中绘制,也可以使用groupbox控件。此时背景色的填充
就是对groupbox控件的填充。
评论