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. QLabel with <img>
Forum Updated to NodeBB v4.3 + New Features

QLabel with <img>

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 196 Views 2 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    I have a png file with a transparent background.

    Heart.png

    which I used with a QLabel like this:

    QString text{ "<img border=\"0\" src=\":/Heart.png\" width=\"20\" height=\"20\">&nbsp;" };
    :
    label.setText(text);
    

    I expected the background of the label to show through, but this is what I actually saw:

    2c4e7599-18a3-4204-b282-f7eb410c2ff1-image.png

    IOW the png wasn't displayed with transparent background?

    What's wrong?

    Thanks, David

    Pl45m4P 1 Reply Last reply
    0
    • Pl45m4P Pl45m4

      @Perdrix said in QLabel with <img>:

      What's wrong?

      You could try

      label.setAttribute(Qt::WA_TranslucentBackground);
      

      Otherwise I would say QLabel::setText combined with HTML code for images doesn't support transparency, but maybe somebody knows better :)

      Never done this way before (with transparency).

      PerdrixP Offline
      PerdrixP Offline
      Perdrix
      wrote on last edited by
      #3

      @Pl45m4 It appeared to have a transparent background but actually had a checker-board background, so it looked right, but wasn't.

      Editing file and making the background truly transparent solved the problem.

      D.

      1 Reply Last reply
      0
      • PerdrixP Perdrix

        I have a png file with a transparent background.

        Heart.png

        which I used with a QLabel like this:

        QString text{ "<img border=\"0\" src=\":/Heart.png\" width=\"20\" height=\"20\">&nbsp;" };
        :
        label.setText(text);
        

        I expected the background of the label to show through, but this is what I actually saw:

        2c4e7599-18a3-4204-b282-f7eb410c2ff1-image.png

        IOW the png wasn't displayed with transparent background?

        What's wrong?

        Thanks, David

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #2

        @Perdrix said in QLabel with <img>:

        What's wrong?

        You could try

        label.setAttribute(Qt::WA_TranslucentBackground);
        

        Otherwise I would say QLabel::setText combined with HTML code for images doesn't support transparency, but maybe somebody knows better :)

        Never done this way before (with transparency).


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        PerdrixP 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @Perdrix said in QLabel with <img>:

          What's wrong?

          You could try

          label.setAttribute(Qt::WA_TranslucentBackground);
          

          Otherwise I would say QLabel::setText combined with HTML code for images doesn't support transparency, but maybe somebody knows better :)

          Never done this way before (with transparency).

          PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #3

          @Pl45m4 It appeared to have a transparent background but actually had a checker-board background, so it looked right, but wasn't.

          Editing file and making the background truly transparent solved the problem.

          D.

          1 Reply Last reply
          0
          • SGaistS SGaist has marked this topic as solved on

          • Login

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