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);

上一篇:Qt 隐藏标题栏 窗口移动 鼠标事件


下一篇:python – QWidget上的QPixmap上的绘图点(pyqt5)