Qt学习笔记——以QWidget为基类的派生类使用背景图片

继承于QWidget的类无法使用 background-imagebackground-border 这两个属性设置背景图片

需要重写一次paintEvent(QPaintEvent * )

void MyWidget::paintEvent(QPaintEvent *){
    //继承与Widget的类无法使用background-image
    //跟background-border
    //需要进行下面的操作,初始化重置一次该widget的style
    //大概是上面这意思吧。。
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

猜你喜欢

转载自blog.csdn.net/qq_15710245/article/details/83034968