Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Cannot create transparent pixmap for QDrag
Forum Updated to NodeBB v4.3 + New Features

Cannot create transparent pixmap for QDrag

Scheduled Pinned Locked Moved Solved Mobile and Embedded
18 Posts 3 Posters 3.4k 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.
  • SGaistS SGaist

    Hi,

    Did you try to have that transparent background while doing simple base painting ?

    B Offline
    B Offline
    Boofish
    wrote on last edited by Boofish
    #3

    @SGaist Hello again and sorry for the delayed response. I just tested this code and it works outside a QDrag. I also had to remove these two lines:

        painter.setBackgroundMode(Qt::BGMode::TransparentMode);
        painter.setCompositionMode(QPainter::CompositionMode_Plus);
    

    they seem to be making the pixmap a bit grey. Not sure why but if I remove them and just call the toPixmap() function and then use the returned pixmap on a test item it works as expected (no white background). On the other hand if I use it on a QDrag then I get the same pixmap but with a white background. Here is the drag code (runs on a mouse move after a long press):

            auto pixmap = toPixmap();
    
            // do drag n drop
            auto drag = new QDrag(event->widget());
    
            QByteArray data;
            QDataStream stream(&data, QIODevice::WriteOnly);
    
            QString strData = QString::number(row()) + ":" + QString::number(column());
            stream << strData;
    
            QMimeData* mimeData = new QMimeData();
            mimeData->setData("application/modelCellData", data);
            drag->setMimeData(mimeData);
            drag->setPixmap(pixmap);
            drag->setHotSpot(QPoint(halfSize().width(), halfSize().height()));
    

    In the test item btw the pixmap is drawn in the paint method like so:

        if (!m_pixmap.isNull())
        {
            QRectF rect = boundingRect();
            painter->setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true);
            painter->setBrush(QBrush(QColor(Qt::transparent)));
            painter->setPen(QPen(QBrush(QColor(Qt::transparent)), 0));
            painter->drawPixmap(rect.x(), rect.y(), rect.width(), rect.height(), m_pixmap);
        }
    

    It looks to me like some sort of blending issue (hence why I was trying those composition and background modes) between the pixmap's or painter's background and whatever I draw on it. But can't figure out what exactly. And then again why would it behave differently when I simply draw the result pixmap and when I use it in a QDrag.

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

      What OS are you running ?
      What version of Qt are you using ?

      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
      0
      • B Offline
        B Offline
        Boofish
        wrote on last edited by Boofish
        #5

        This is happening both on my dev machine which is running:

        Ubuntu 18.04.1 LTS

        as well as on the target board which is running:

        NAME=Buildroot
        VERSION=2015.02
        ID=buildroot
        VERSION_ID=2015.02
        PRETTY_NAME="Buildroot 2015.02"

        I am using Qt version 4.8.6 on both of them.

        Worth mentioning as its already shown here that I'm using buildroot for the target board OS and from what I've read in other posts its a PITA if at all possible to replace the Qt version on it (https://stackoverflow.com/questions/50024991/how-to-tell-buildroot-to-use-a-different-version-of-source-code-of-qt). So if this is a Qt issue in this specific version and not wrong usage on my side I would really like to patch it if possible instead of upping the version.

        Also I did try using Qt5 as there is an option in buildroot in menuconfig and used bare bones Qt with just the addition of PNG support and that resulted in a kernel panic. So it does seem like it will be a painful experience if I do indeed have to go down that route.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Boofish
          wrote on last edited by Boofish
          #6

          Probably worth noting that even if I just do this:

                  QPixmap pixmap(size().width(), size().height());
                  pixmap.fill(Qt::transparent);
                  ...
                  drag->setPixmap(pixmap);
          

          I still get a white pixmap. On both OS's. So this doesn't seem related to my toPixmap() function at all.

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

            Are you using your own build of Qt ?

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

            B 1 Reply Last reply
            0
            • SGaistS SGaist

              Are you using your own build of Qt ?

              B Offline
              B Offline
              Boofish
              wrote on last edited by Boofish
              #8

              @SGaist No. On my dev machine I use open source qt that I installed either via apt-get install or by downloading the package and installing it. Can't remember which of the two but I certainly didn't build it manually. And on the board I use buildroot as mentioned already. Obviously, for the board build buildroot downloads and builds it. But I have not applied any patches on that so far either.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Boofish
                wrote on last edited by Boofish
                #9

                Sorry for the downvote on your previous post btw but the answer to one of your questions is already mentioned in my original question (i.e. qt version 4.8.6).

                SGaistS 1 Reply Last reply
                0
                • B Boofish

                  Sorry for the downvote on your previous post btw but the answer to one of your questions is already mentioned in my original question (i.e. qt version 4.8.6).

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @Boofish said in Cannot create transparent pixmap for QDrag:

                  Sorry for the downvote on your previous post btw but the answer to one of your questions is already mentioned in my original question (i.e. qt version 4.8.6).

                  While I did miss you wrote the Qt version, the OS you are using is still legitimate, especially if you are using different flavours of Linux.

                  Note that you are not even using the latest version of the Qt 4 series and also it has reached end of life a long time ago now.

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

                  B 1 Reply Last reply
                  2
                  • SGaistS SGaist

                    @Boofish said in Cannot create transparent pixmap for QDrag:

                    Sorry for the downvote on your previous post btw but the answer to one of your questions is already mentioned in my original question (i.e. qt version 4.8.6).

                    While I did miss you wrote the Qt version, the OS you are using is still legitimate, especially if you are using different flavours of Linux.

                    Note that you are not even using the latest version of the Qt 4 series and also it has reached end of life a long time ago now.

                    B Offline
                    B Offline
                    Boofish
                    wrote on last edited by Boofish
                    #11

                    @SGaist Retracted the downvote. But anyway I would still like to fix the issue on this qt version preferably, for the reason I mentioned. I mean I'd like to identify the actual problem so if anyone knows what the bug is if it is indeed a bug, I can surely patch it. Also when you say "it has reached end of life a long time ago now" do you mean Qt4.8.6 or Qt4 in general?

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

                      Qt 4. There won't be any new bug fixes release unless there's a highly critical security issue. See here.

                      One thing you can still try is Qt 4.8.7 if you can't update to a recent supported version of Qt.

                      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
                      2
                      • B Offline
                        B Offline
                        Boofish
                        wrote on last edited by Boofish
                        #13

                        Thanks for the responses. I'll try upping the version. I'll also dig into the code a bit more because the drag n drop robot example... works. Which is suspicious. And that is also using a pixmap in a QDrag from what I see.

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          Boofish
                          wrote on last edited by Boofish
                          #14

                          I'm going to leave this open in case I do find a solution, be it upping the version or whatever else (a quick google search shows that I'm not the only one that has had this issue or similar issues). I'll post it if I do maybe it will be helpful to someone else.

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

                            One thing that could help is to provide a minimal compilable example that reproduces that. So other people may have a look at it more easily.

                            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
                            • B Offline
                              B Offline
                              Boofish
                              wrote on last edited by
                              #16

                              I've found the solution. I had to patch qt source code to get this working. Here is the patch for anyone else struggling with this:

                              --- qt.old/src/gui/kernel/qdnd_qws.cpp	2019-07-04 02:22:03.051763167 +0300
                              +++ qt/src/gui/kernel/qdnd_qws.cpp	2019-07-04 02:22:36.895605031 +0300
                              @@ -97,6 +97,7 @@
                                       // setAttribute() should be done unconditionally!
                                       if (QApplication::type() == QApplication::GuiServer)
                                           setAttribute(Qt::WA_TransparentForMouseEvents);
                              +	setAttribute(Qt::WA_TranslucentBackground);
                                   }
                               
                                   void setPixmap(QPixmap pm)
                              --- qt.old/src/gui/kernel/qdnd_x11.cpp	2019-07-04 02:22:54.539523527 +0300
                              +++ qt/src/gui/kernel/qdnd_x11.cpp	2019-07-04 02:22:12.647718085 +0300
                              @@ -286,6 +286,7 @@
                                               | Qt::BypassGraphicsProxyWidget)
                                   {
                                       setAttribute(Qt::WA_X11NetWmWindowTypeDND);
                              +	setAttribute(Qt::WA_TranslucentBackground);
                                   }
                               
                                   void setPixmap(const QPixmap &pm)
                              
                              jsulmJ 1 Reply Last reply
                              0
                              • B Boofish

                                I've found the solution. I had to patch qt source code to get this working. Here is the patch for anyone else struggling with this:

                                --- qt.old/src/gui/kernel/qdnd_qws.cpp	2019-07-04 02:22:03.051763167 +0300
                                +++ qt/src/gui/kernel/qdnd_qws.cpp	2019-07-04 02:22:36.895605031 +0300
                                @@ -97,6 +97,7 @@
                                         // setAttribute() should be done unconditionally!
                                         if (QApplication::type() == QApplication::GuiServer)
                                             setAttribute(Qt::WA_TransparentForMouseEvents);
                                +	setAttribute(Qt::WA_TranslucentBackground);
                                     }
                                 
                                     void setPixmap(QPixmap pm)
                                --- qt.old/src/gui/kernel/qdnd_x11.cpp	2019-07-04 02:22:54.539523527 +0300
                                +++ qt/src/gui/kernel/qdnd_x11.cpp	2019-07-04 02:22:12.647718085 +0300
                                @@ -286,6 +286,7 @@
                                                 | Qt::BypassGraphicsProxyWidget)
                                     {
                                         setAttribute(Qt::WA_X11NetWmWindowTypeDND);
                                +	setAttribute(Qt::WA_TranslucentBackground);
                                     }
                                 
                                     void setPixmap(const QPixmap &pm)
                                
                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #17

                                @boofish If this is really a Qt issue and you have a patch you should contribute it to Qt, so it gets integrated.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                B 1 Reply Last reply
                                1
                                • jsulmJ jsulm

                                  @boofish If this is really a Qt issue and you have a patch you should contribute it to Qt, so it gets integrated.

                                  B Offline
                                  B Offline
                                  Boofish
                                  wrote on last edited by
                                  #18

                                  @jsulm Hi jsulm, this is on qt 4.8. I don't think this file even exists in the latest qt version.

                                  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