QPushButton from PNG with alpha overlayed on QGraphicsPixmapItem
-
I am trying to draw a translucent button on top of a QGraphicsPixmapItem. My setup looks like this:
QIcon* playButtonIcon = new QIcon("/path/to/buttonImage.png"); QPushButton* m_playButton = new QPushButton; m_playButton->setIcon(*m_playIcon); QString frontPath = "/path/to/pixmap"; m_frontPixmap = new QPixmap(frontPath); m_frontItem = new QGraphicsPixmapItem(*m_frontPixmap); m_scene = new QGraphicsScene(-300,0,600,600, this); this->setScene(m_scene); m_scene->addItem(m_frontItem); QGraphicsProxyWidget* gpw = m_scene->addWidget(m_playButton);
This renders the button on top of the pixmap, but instead of a transparent blackground I get a black box. So, either the alpha channel is being rendered as black or there is a black layer somewhere behind the QPushButton (but still in front of the pixmap).
I've tried applying transparency everywhere I can think to:
m_playButton->setStyleSheet("QPushButton{background-color: transparent;}"); // And a few other variants of this
QPalette button_palette(m_playButton->palette()); button_palette.setColor(QPalette::Button, Qt::color0); m_playButton->setPalette(button_palette);
...to give a couple examples. Needless to say, none of these change (or resolve) the issue.
Does anybody know what's going on here? How to get what I want?
-
Hi
Did you try
m_playButton ->setAttribute(Qt::WA_TranslucentBackground); -
Hi,
Did you also try
m_playButton->setStyleSheet("background: transparent; border: none")
?In any case, depending on the look and feel you are wanting, you should consider implementing the controls also using QGraphicsItem.
-
I have observed that
@SGaist said in QPushButton from PNG with alpha overlayed on QGraphicsPixmapItem:
Hi,
Did you also try
m_playButton->setStyleSheet("background: transparent; border: none")
?In any case, depending on the look and feel you are wanting, you should consider implementing the controls also using QGraphicsItem.
Yes, I basically came to the same conclusion. QPushButton is a convenience, except that in this case it isn't at all. I can draw the button and capture mouse click events any number of ways. I noticed that QLabel's transparency works here, but then I still need a QGraphicsProxyWidget. Why not cut out the middleman altogether?
Thanks.