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. [Solved] QSplashScreen using a PNG with transparent areas
Forum Updated to NodeBB v4.3 + New Features

[Solved] QSplashScreen using a PNG with transparent areas

Scheduled Pinned Locked Moved General and Desktop
27 Posts 7 Posters 29.9k 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.
  • D Offline
    D Offline
    d.oberkofler
    wrote on last edited by
    #1

    Should the QSplashScreen class support the use of a PNG with transparent areas?

    My code looks as follows:

    @
    QPixmap aPixmap(":/splash.png");
    aSplashScreen = new QSplashScreen(aPixmap);
    aSplashScreen->setMask(aPixmap.mask());
    aSplashScreen->show();
    @

    Instead of seeing the background in the transparent areas I just seem them white.

    Thank you in advance!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      If the png is transparent, you will see the widget background (which might be white :-( ).
      You could try making the QSplashScreen object with "transparent background":https://developer.qt.nokia.com/forums/viewthread/1254

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • U Offline
        U Offline
        ucomesdag
        wrote on last edited by
        #3

        Did you set the correct window flags?

        @setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen)@

        Write “Qt”, not “QT” (QuickTime).

        1 Reply Last reply
        0
        • D Offline
          D Offline
          d.oberkofler
          wrote on last edited by
          #4

          [quote author="ucomesdag" date="1294872786"]Did you set the correct window flags?
          @setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen)@[/quote]

          I double checked the QSplashScreen documentation (clearly test it as well) and it seems to me as if Qt::WindowStaysOnTopHint hint would be optional and Qt::SplashScreen redundant.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            d.oberkofler
            wrote on last edited by
            #5

            [quote author="Gerolf" date="1294865945"]If the png is transparent, you will see the widget background (which might be white :-( ).
            You could try making the QSplashScreen object with "transparent background":https://developer.qt.nokia.com/forums/viewthread/1254
            [/quote]

            I've tried to understand how the information in your link relates to QSplashScreen but I'm not sure on what to do. Would you be so kind and explain in more detail on how you think I can make the QSplashScreen object with "transparent background". A small example would be most appreciated.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              d.oberkofler
              wrote on last edited by
              #6

              I have in the meantime done some more testing and it is interesting to see what the different in using the
              @aSplashScreen->setMask(aPixmap.mask());@ line makes:

              without using setMask: !http://img407.imageshack.us/img407/738/hc014.png!

              when using setMask: !http://img163.imageshack.us/img163/9548/hc013.png!

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                That has a similar effect, but a mask does not make alpha, it makes transparent or not.

                A top level widget (QSplashScreen is a widget) can be transparent. Sorry, I didn't read the complete article before. Currently I can't test it, but you could play with the following things:

                • setWindowOpacity(xxx);
                • setAttribute(Qt::WA_NoBackground);
                • setAttribute(Qt::WA_NoSystemBackground);
                • setAttribute(Qt::WA_TranslucentBackground);

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  d.oberkofler
                  wrote on last edited by
                  #8

                  [quote author="Gerolf" date="1294907465"]That has a similar effect, but a mask does not make alpha, it makes transparent or not.

                  A top level widget (QSplashScreen is a widget) can be transparent. Sorry, I didn't read the complete article before. Currently I can't test it, but you could play with the following things:

                  • setWindowOpacity(xxx);
                  • setAttribute(Qt::WA_NoBackground);
                  • setAttribute(Qt::WA_NoSystemBackground);
                    [/quote]

                  Thank you for the additional information but unfortunately it seem not to solve my problem:

                  setWindowOpacity(.75);
                  Makes the complete widget 75% translucent but does not affect the area using the alpha channel.

                  setAttribute(Qt::WA_NoBackground);
                  setAttribute(Qt::WA_NoSystemBackground);
                  setAttribute(Qt::WA_TranslucentBackground);
                  All tree attributes just make the background of the window black and the area involved depends on the use of setMask.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mohsen
                    wrote on last edited by
                    #9

                    what OS you're using?

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      d.oberkofler
                      wrote on last edited by
                      #10

                      Currently testing on OSX and Windows.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dangelog
                        wrote on last edited by
                        #11

                        Use a QLabel instead.

                        http://bugreports.qt.nokia.com/browse/QTBUG-12820

                        Software Engineer
                        KDAB (UK) Ltd., a KDAB Group company

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mohsen
                          wrote on last edited by
                          #12

                          if the form transparency is the problem, there wont be difference in using objects.

                          [quote author="peppe" date="1294920580"]Use a QLabel instead.

                          http://bugreports.qt.nokia.com/browse/QTBUG-12820[/quote]

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            d.oberkofler
                            wrote on last edited by
                            #13

                            [quote author="peppe" date="1294920580"]Use a QLabel instead.
                            http://bugreports.qt.nokia.com/browse/QTBUG-12820[/quote]

                            Thank you for the hint! I really seem to have hit bug 12820.

                            The following code seems to work as expected:
                            @
                            QPixmap aPixmap(":/splash.png");
                            QLabel* aWidget = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
                            aWidget->setAttribute(Qt::WA_TranslucentBackground);
                            aWidget->setPixmap(aPixmap);
                            aWidget->show();
                            @

                            I'm actually surprised to hit a bug in a rather prominent class like QSplashScreen. As there is no information on when this bug will be fixed it might make sense to vote for it.

                            Does someone eventually have a workaround to get this working in a QSplashScreen?

                            1 Reply Last reply
                            0
                            • U Offline
                              U Offline
                              ucomesdag
                              wrote on last edited by
                              #14

                              I got it working by subclassing QSplashScreen, setting QSplashScreen::setPixmap(QPixmap splash); and setting the mask to the subclass, setMask(QPixmap mask); .

                              Splash image with a text display:

                              !http://img.mobypicture.com/aa470873918e7804b36e6fb037e5b0b0_view.jpg(screencap)!

                              main:
                              @QPixmap splashImage(":images/splash.png");
                              QPixmap splashMask(":images/splashmask.png");

                              customSplashScreen *splash = new customSplashScreen(splashImage);
                              splash->setMessageRect(QRect::QRect(7, 253, 415, 14), Qt::AlignCenter); // Setting the message position.

                              QFont splashFont;
                              splashFont.setFamily("Arial");
                              splashFont.setBold(true);
                              splashFont.setPixelSize(9);
                              splashFont.setStretch(125);

                              splash->setFont(splashFont);
                              splash->setMask(splashMask);
                              splash->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen);
                              splash->show();

                              /* To intercept mousclick to hide splash screen. Since the
                              splash screen is typically displayed before the event loop
                              has started running, it is necessary to periodically call. */
                              app.processEvents();

                              splash->showStatusMessage(QObject::tr("Initializing..."));@

                              customSplashScreen.h:
                              @#ifndef CUSTOMSPLASHSCREEN_H
                              #define CUSTOMSPLASHSCREEN_H

                              #include <QSplashScreen>
                              #include <QPainter>

                              class customSplashScreen
                              :public QSplashScreen
                              {

                              public:
                              customSplashScreen(const QPixmap& pixmap);
                              ~customSplashScreen();
                              virtual void drawContents(QPainter *painter);
                              void showStatusMessage(const QString &message, const QColor &color = Qt::black);
                              void setMessageRect(QRect rect, int alignment = Qt::AlignLeft);

                              private:
                              QString message;
                              int alignement;
                              QColor color;
                              QRect rect;
                              };

                              #endif // CUSTOMSPLASHSCREEN_H@

                              customSplashScreen.cpp:
                              @#include "customSplashScreen.h"

                              customSplashScreen::customSplashScreen(const QPixmap& pixmap)
                              {
                              QSplashScreen::setPixmap(pixmap);
                              };

                              customSplashScreen::~customSplashScreen()
                              {
                              };

                              void customSplashScreen::drawContents(QPainter *painter)
                              {
                              QPixmap textPix = QSplashScreen::pixmap();
                              painter->setPen(this->color);
                              painter->drawText(this->rect, this->alignement, this->message);
                              };

                              void customSplashScreen::showStatusMessage(const QString &message, const QColor &color)
                              {
                              this->message = message;
                              this->color = color;
                              this->showMessage(this->message, this->alignement, this->color);
                              };

                              void customSplashScreen::setMessageRect(QRect rect, int alignement)
                              {
                              this->rect = rect;
                              this->alignement = alignement;
                              };@

                              Write “Qt”, not “QT” (QuickTime).

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                d.oberkofler
                                wrote on last edited by
                                #15

                                [quote author="ucomesdag" date="1295004120"]I got it working by subclassing QSplashScreen, setting QSplashScreen::setPixmap(QPixmap splash); and setting the mask to the subclass, setMask(QPixmap mask); .

                                Splash image with a text display:

                                !http://img.mobypicture.com/aa470873918e7804b36e6fb037e5b0b0_view.jpg!
                                [/quote]

                                Thank you very much!
                                Your approach look very promising.
                                How exactly did you setup (alpha channel) the two images you are using?

                                1 Reply Last reply
                                0
                                • U Offline
                                  U Offline
                                  ucomesdag
                                  wrote on last edited by
                                  #16

                                  The splash image:
                                  !http://img.mobypicture.com/4ffeff271423757e1833f553a292bd1c_view.jpg(splash)!

                                  and the mask:
                                  !http://img.mobypicture.com/158962e6c51d76d0bfe042338fb27d6e_view.jpg(mask)!

                                  Write “Qt”, not “QT” (QuickTime).

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    goetz
                                    wrote on last edited by
                                    #17

                                    Do you mind creating a wiki article in the "HowTo":http://developer.qt.nokia.com/wiki/Category:HowTo and/or "Code snippets":http://developer.qt.nokia.com/wiki/Category:snippets category? It would fit very well there!

                                    http://www.catb.org/~esr/faqs/smart-questions.html

                                    1 Reply Last reply
                                    0
                                    • U Offline
                                      U Offline
                                      ucomesdag
                                      wrote on last edited by
                                      #18

                                      [quote author="Volker" date="1295008017"]Do you mind creating a wiki article in the "HowTo":http://developer.qt.nokia.com/wiki/Category:HowTo and/or "Code snippets":http://developer.qt.nokia.com/wiki/Category:snippets category? It would fit very well there![/quote]

                                      Will do so!

                                      Write “Qt”, not “QT” (QuickTime).

                                      1 Reply Last reply
                                      0
                                      • U Offline
                                        U Offline
                                        ucomesdag
                                        wrote on last edited by
                                        #19

                                        Wiki: "splashscreen snippet":http://developer.qt.nokia.com/wiki/Custom_splashscreen_with_text

                                        Write “Qt”, not “QT” (QuickTime).

                                        1 Reply Last reply
                                        0
                                        • D Offline
                                          D Offline
                                          d.oberkofler
                                          wrote on last edited by
                                          #20
                                          • I have an image with an Alpha channel: am I correct in the assumption that the image (splash.png) you've used has no alpha channel and the mask (splashmask.png) is the (1 bit) alpha channel?

                                          • If the above assumptions are correct I still seem to have problems with the semi-transparent parts of my image. In my case there is a shadow that uses a multibit alpha channel that is not shown correctly.

                                          • For now I'm only able to show my splash screen properly using the following code:
                                            @QPixmap aPixmap(":/splash.png");
                                            QLabel* aWidget = new QLabel(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
                                            aWidget->setAttribute(Qt::WA_TranslucentBackground);
                                            aWidget->setPixmap(aPixmap);
                                            aWidget->show();
                                            @

                                          • Is there maybe a way to have QSplashScreen show the images in the same way as QLabel does when using the Qt::WA_TranslucentBackground attribute ?

                                          • Is there maybe a way to to use QLabel as an alternative to QSplashScreen and add something similar to showMessage to the QLabel ?

                                          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