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. I want to show a png file contained alpha channel in a top window properly.
Forum Updated to NodeBB v4.3 + New Features

I want to show a png file contained alpha channel in a top window properly.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views 1 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.
  • L Offline
    L Offline
    lygstate
    wrote on last edited by
    #1

    How to do that?
    I am using win7 + qt 5.1.1.
    When the window is show, i want to see the desktop if the png's pixel's alpha value is 0.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      Have a look at the following code "snippet for setting semi-transparent background color of a QWidget":http://qt-project.org/wiki/QWidget_Semi-transparent_Background_Color. Class QMainWindow also contains method paintEvent so you do an overriding just like in the example for QWidget. As you can see the code snippet uses QColor and QPainter. Adjust the transparency using method setAlpha which value is in range 0 to 255. A png can be drawn using method "drawImage of class QPainter":http://qt-project.org/doc/qt-5.0/qtgui/qpainter.html#drawImage

      As "an alternative solution may this example using WA_TranslucentBackground":http://www.codeprogress.com/cpp/libraries/qt/showQtExample.php?index=191&key=QMainWindowTransparentBg might be useful too.

      http://anavi.org/

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lygstate
        wrote on last edited by
        #3

        Now, I know I am asking a wrong question.
        For this question, the answer code
        @
        int main() {
        /* Show transparent picture in a top window */
        QImage image(":/images/assdqw.png");
        QPainter p;
        p.begin(&image);
        p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        p.fillRect(image.rect(), QColor(0, 0, 0, 255));
        p.end();

        QLabel *l = new QLabel(NULL, Qt::FramelessWindowHint);
        l->setAttribute(Qt::WA_TranslucentBackground, true);
        l->setPixmap(QPixmap::fromImage(image));
        l->show();
        

        }
        @

        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