Qt Qpushbutton设置背景色的问题

今天发现一个问题,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的大小

你可能感兴趣的:(qt)