<分区>
我刚刚开始学习 QT,我真的需要一些帮助。我想用(仅)一个图像(不显示任何边框或轮廓)制作一个按钮,并且我还需要能够在鼠标悬停在图像上和离开图像时更改图像。有帮助吗?
<分区>
我刚刚开始学习 QT,我真的需要一些帮助。我想用(仅)一个图像(不显示任何边框或轮廓)制作一个按钮,并且我还需要能够在鼠标悬停在图像上和离开图像时更改图像。有帮助吗?
最佳答案
I want to make a button out of (just) an Image (not showing any border or outline), and I also need to be able to change the image when the mouse is hovering over the image and off the image. Any help?
也许最简单的方法是使用 QPushButton:
// the button has to be somehow initialized and maybe added to layout
QPushButton* pMyPushButton = new QPushButton(this);
layout()->AddWidget(pMyPushButton);
// try style it like that
// the concrete example limits the scope to pMyPushButton object
pMyPushButton->setStyleSheet(
"QPushButton {"
"background: transparent;"
"image: url(res/images/normal_bn_image.png);"
"}"
"QPushButton:hover {"
"image: url(res/images/hover_bn_image.png);"
"}"
);
确保提供正确的图像 URL。也许这可以稍微澄清图像资源:Unable to set the background image in Qt Stylesheet
关于c++ - QT中如何制作带触发器的图片按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35658710/