我用setStyleSheet的时候很疑惑,想做多个按钮,每个按钮点击的时候会切换同的png图,为什么用setStyleSheet的时候,只有一个是切换了,其它按钮没有切换图片呢?代码如下:
QPushButton* btn = new QPushButton(this);
btn->setGeometry(10, 10, 200, 200);
btn->setStyleSheet("QPushButton {border-image:url(/PocketMory1/png/off1.png); font-size:24px;} \
QPushButton:hover:pressed {border-image:url(/PocketMory1/png/on1.png);font-size:24px;} \
QPushButton:hover:!pressed {border-image:url(/PocketMory1/png/off1.png);font-size:24px;} ");
btn->setFlat(true);
btn->show();
QPushButton* btn2 = new QPushButton(this);
btn2->setGeometry(150, 150, 200, 200);
btn2->setStyleSheet("QPushButton {border-image:url(/PocketMory1/png/off2.png); font-size:24px;} \
QPushButton:hover:pressed {border-image:url(/PocketMory1/png/on2.png);font-size:24px;} \
QPushButton:hover:!pressed {border-image:url(/PocketMory1/png/off2.png);font-size:24px;} ");
btn2->setFlat(true);
btn2->show();
这样哪里不对呢?代码是在继承的对话框的初始化中。