您的位置:首页 > 编程语言 > Qt开发

Qt Qpushbutton设置背景色的问题

2015-01-11 22:13 966 查看
今天发现一个问题,Qt Qpushbutton设置背景色只能用代码如下设置,StyleSheet在qt creator中居然只能设置前景色!!!
pushbutton->setStyleSheet("background-color:rgb(234,234,234)");
如下使用palette也无法设置背景色!
QPalette P=pushbutton->palette();
P.setColor(QPalette::Window,Qt::green);
P.setBrush(QPalette::Window,Qt::blue);
P.setColor(QPalette::ButtonText,Qt::red);
pushbutton->setPalette(P);
pushbutton->setBackgroundRole(QPalette::Button);
pushbutton->setAutoFillBackground(true);
http://blog.chinaunix.net/uid-25808509-id-1746294.html
http://www.cppblog.com/qianqian/archive/2010/07/25/121238.html
pushbutton=new QPushButton(tr("返回"),this);
QPalette P=pushbutton->palette();
P.setColor(QPalette::Window,Qt::green);
P.setBrush(QPalette::Window,Qt::blue);
P.setColor(QPalette::ButtonText,Qt::red);
pushbutton->setPalette(P);
pushbutton->setBackgroundRole(QPalette::Button);
pushbutton->setAutoFillBackground(true);
pushbutton->setStyleSheet("background-color:rgb(234,234,234)");
//    pushbutton->move(200,300);//设置子widget相对父widget中的位置
pushbutton->setGeometry(200,300,50,50);//设置子widget相对父widget中的位置及该widget的大小
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: