Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPushButton from PNG with alpha overlayed on QGraphicsPixmapItem

QPushButton from PNG with alpha overlayed on QGraphicsPixmapItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marshaul
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Did you try
      m_playButton ->setAttribute(Qt::WA_TranslucentBackground);

      1 Reply Last reply
      0
      • M Offline
        M Offline
        marshaul
        wrote on last edited by
        #3

        @mrjj said in QPushButton from PNG with alpha overlayed on QGraphicsPixmapItem:

        m_playButton ->setAttribute(Qt::WA_TranslucentBackground);

        Yes, but no change. :(

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • M Offline
            M Offline
            marshaul
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved