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. How to set the background of Qimage to transparent?
Forum Updated to NodeBB v4.3 + New Features

How to set the background of Qimage to transparent?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 12.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.
  • Y Offline
    Y Offline
    yhodage
    wrote on last edited by
    #1

    Hi,

    i am new to Qt programming. i have created the Qimage object by providing image[.png] file.
    ex.
    Qimage image("some.png").

    i am using qt 4.8

    please help me to set transparent background of image. currently it shows black background.

    Thank You

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      you can try to convert the QImage:
      @
      image = image.convertToFormat(QImage::Format_ARGB32);
      @
      Assuming the PNG file really has a alpha channel set.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yhodage
        wrote on last edited by
        #3

        Hi,
        i checked the format and it has Format_ARGB32. also i have checked the alpha set by using hasAlphaChannel () Api and it returns true.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          yhodage
          wrote on last edited by
          #4

          Hi ,

          one more thing i forgot to tell u that i am generating custom Qcursor from the image.
          Ex
          Qimage image(“some.png”).
          QBitmap(image.size());

          QCurosr(image,mask,hot_spot_x,hot_spot_y);

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            so why don't you just use QPixmap directly?
            @
            widget->setCursor( QCursor( QPixmap("image.png") ) );
            @

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yhodage
              wrote on last edited by
              #6

              Hi ,

              I did what you say but did not get transparent background for the custom curosr

              1 Reply Last reply
              0
              • Y Offline
                Y Offline
                yhodage
                wrote on last edited by
                #7

                Hi ,

                actually i am converting my application from 3.0 to 4.8. the code for custom cursor is already implemented. it works fine it qt 3.0. cursor has transparent background when it works in qt 3.0. but when i test same code in qt 4.8 it shows black background.
                Ex code snippet.
                Qimage image
                Qimage image1(image.size(),1,2,Qimage::BigEndian);
                Qimage image1_mask(image.size(),1,2,Qimage::BigEndian);
                int hot_x=-1;
                int hot_y=-1

                setPixel according to height and width of Qimage object.

                QBitmap bit(image1.size())
                Qbitmap bt_map(image1_mask.size())

                new Qcursor(bt,bt_map,hot_x,hot_y);

                is anything wrong here. please help me i have tried several combination for this

                Thank You

                1 Reply Last reply
                0
                • Y Offline
                  Y Offline
                  yhodage
                  wrote on last edited by
                  #8

                  Hi ,

                  Please anybody knows this issue ..... i am stuck with this

                  Thanks

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    can you post the cursor image (png file)?

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • IamSumitI Offline
                      IamSumitI Offline
                      IamSumit
                      wrote on last edited by
                      #10

                      Hello yhodage,

                      Try this combination...[Qt 4.8]
                      If You have transparent cursor image then it would be good ,other wise make cursor png to transparent.
                      QPixmap map("some.png");
                      QCursor mCursor(map);
                      setCursor(mCursor);

                      Be Cute

                      1 Reply Last reply
                      0
                      • Y Offline
                        Y Offline
                        yhodage
                        wrote on last edited by
                        #11

                        Hi ,

                        i had tried that one but no result. actually a black box appears around the custom cursor. the image that is used in custom cursor is not transparent but with the code snippet that i had paste earlier works with not transparent image in qt 3.0. i just port my application to qt 4.8 and the problem starts here.

                        please help me to resolve this issue.

                        Thanks

                        1 Reply Last reply
                        0
                        • Y Offline
                          Y Offline
                          yhodage
                          wrote on last edited by
                          #12

                          I just want to set transparent background of cursor. currently it shows black background around the cursor

                          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