QWidget添加带有图片的QPushButton

QWidget* w = new QWidget(this);

w->setGeometry(10,20,400,300);

QVBoxLayout* layout = new QVBoxLayout(w);

layout->setSpacing(0);

layout->setContentMargins(0,0,0,0);

QPushButton* b = new QPushButton(w);

b->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);

layout->addWidget(b);

QString style = "QPushButton{image:url(:/normal.png);border-style:none;}

style += "QPushButton:hover{image:url(:/hover.png);border-style:none;}

style += "QPushButton:pressed{image:url(:/pressed.png);border-style:none;}

b->setStyleSheet(style);

猜你喜欢

转载自www.cnblogs.com/coolbear/p/11769960.html