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 add transparency image in QT5.5.1 ?
Forum Updated to NodeBB v4.3 + New Features

How to add transparency image in QT5.5.1 ?

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

    Hi,

    Now I am trying to add transparency image in qt.5.5.1. It is not working .But it is works well in qt 4.8.7.

    My sample code is below,

       QLabel* bg = new QLabel(&w);
    bg->setGeometry(100, 100, 200, 200);
    bg->show();
    bg->setText("Hello");
    bg->setStyleSheet("background-color: yellow;");
        QPushButton* trans = new QPushButton(&w);
    trans->setGeometry(100, 100, 200, 200);
    QPixmap pixmap("transparent.png");
    QIcon ButtonIcon(pixmap);
    trans->setIcon(ButtonIcon);
    trans->setIconSize(trans->size());
    trans->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
    

    This is works good in my pc. Am I need to change any code for qt 5.5.1? I am using X86 processor machine to run this code.

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

      Hi
      Are you sure it find the
      QPixmap pixmap("transparent.png"); ?

      R 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        Are you sure it find the
        QPixmap pixmap("transparent.png"); ?

        R Offline
        R Offline
        Revathi
        wrote on last edited by
        #3

        @mrjj Yes it found the image correctly. That's why it is working correctly in qt 4.8.7 version if I change the Kit configuration.

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

          Ok so how does it "not work" ?
          if i use your code ( with less trans ) i see
          alt text

          1 Reply Last reply
          0
          • R Revathi

            @mrjj Yes it found the image correctly. That's why it is working correctly in qt 4.8.7 version if I change the Kit configuration.

            RatzzR Offline
            RatzzR Offline
            Ratzz
            wrote on last edited by
            #5

            @Revathi said in How to add transparency image in QT5.5.1 ?:

            if I change the Kit configuration.

            Do you get any error after changing kit and running the same code with 5.5.1?

            --Alles ist gut.

            R 1 Reply Last reply
            0
            • RatzzR Ratzz

              @Revathi said in How to add transparency image in QT5.5.1 ?:

              if I change the Kit configuration.

              Do you get any error after changing kit and running the same code with 5.5.1?

              R Offline
              R Offline
              Revathi
              wrote on last edited by
              #6

              @Ratzz no. I did not get any error while changing kit.

              mrjjM 1 Reply Last reply
              0
              • R Revathi

                @Ratzz no. I did not get any error while changing kit.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Revathi
                but what do you see ?
                "It is not working" is a very poor description of your actual issue.

                R 1 Reply Last reply
                0
                • mrjjM mrjj

                  @Revathi
                  but what do you see ?
                  "It is not working" is a very poor description of your actual issue.

                  R Offline
                  R Offline
                  Revathi
                  wrote on last edited by
                  #8

                  @mrjj 0_1545906306706_trans.png

                  I am getting like this only.

                  mrjjM 1 Reply Last reply
                  0
                  • R Revathi

                    @mrjj 0_1545906306706_trans.png

                    I am getting like this only.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Revathi
                    Ok
                    Its working here with Qt5.12
                    Can you try
                    trans->setGeometry(100, 100, 180, 180);
                    ( make buttons slightly less than yellow label)

                    R 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @Revathi
                      Ok
                      Its working here with Qt5.12
                      Can you try
                      trans->setGeometry(100, 100, 180, 180);
                      ( make buttons slightly less than yellow label)

                      R Offline
                      R Offline
                      Revathi
                      wrote on last edited by
                      #10

                      @mrjj 0_1545907796414_step2.png

                      If I have changed geometry , the output will be like the above picture (in qt 5.5.1)

                      mrjjM 1 Reply Last reply
                      0
                      • R Revathi

                        @mrjj 0_1545907796414_step2.png

                        If I have changed geometry , the output will be like the above picture (in qt 5.5.1)

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Revathi
                        Ok. just a test.
                        Maybe its something in 5.5.1. Can you try a newer version ?

                        R 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @Revathi
                          Ok. just a test.
                          Maybe its something in 5.5.1. Can you try a newer version ?

                          R Offline
                          R Offline
                          Revathi
                          wrote on last edited by
                          #12

                          @mrjj the transparency is working now in qt 5.5.1. The code is given below,

                          QLabel* bg = new QLabel(&w);
                          bg->setGeometry(100, 100, 200, 200);
                          bg->show();
                          bg->setText("Hello");
                          bg->setStyleSheet("background-color: yellow;");
                          
                          QPushButton* trans = new QPushButton(&w);
                          trans->setGeometry(100, 100, 200, 200);
                          QPixmap pixmap("transparent.png");
                          QIcon ButtonIcon(pixmap);
                          trans->setIcon(ButtonIcon);
                          trans->setIconSize(trans->size());
                          trans->setStyleSheet("border: None");        // It will make the image button as transparent
                          trans->show();
                          

                          If I have changed background color of QLabel, it will transparent to the image button window.

                          I hope it may help. Thank you all.

                          1 Reply Last reply
                          1

                          • Login

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