我在视频前面创建了一个按钮(使用 QVideoWidget 和 QMediaPlayer)。我正在使用具有透明背景的图像来设置图像按钮。
如何将 QPushbutton 设置为透明,但里面的图像可见?我尝试将其设置为透明,但图像的背景变成黑色。
我试过这个 C++ over Qt : Controlling transparency of Labels and Buttons但它不起作用。我试过这个:
ui->btn_Touchme->setAttribute(Qt::WA_TranslucentBackground);
ui->btn_Touchme->setStyleSheet("QPushButton{background: transparent;}");
ui->btn_Touchme->setAttribute(Qt::WA_NoSystemBackground, true);
ui->btn_Touchme->setAttribute(Qt::WA_TranslucentBackground, true);
它仍然是黑色的
我尝试使用 QLabel,但得到了相同的结果。对我有什么建议吗?
我使用的是 qt 5.3.2 和 ubuntu 14.04LTS
最佳答案
如果可以在鼠标悬停在按钮上时显示按钮边距,您可以使用 QToolButton
与 autoRaise
设置为 true
.
此外,您也可以设置以下样式表,即使鼠标悬停在按钮上时也使按钮透明。
ui->btn_Touchme->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
关于qt - 如何将带有图像和透明背景的按钮添加到 QVideoWidget?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29941464/