Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-67541

QLabel paints improper background when using HTML content

    XMLWordPrintable

Details

    • macOS, Windows

    Description

      When HTML content is set as a QLabel text, it starts painting the wrong background (presumably, inherited from the containing widget) instead of the transparent. It's noticeable when using non-solid (gradient, pixmap, etc.) backgrounds in parents.

      Example Screenshot

      // Main Window:
      
      MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
      {
          resize(400, 300);
          GradientWidget *widget = new GradientWidget;
          setCentralWidget(widget);
          QVBoxLayout *layout = new QVBoxLayout(widget);
          layout->addWidget(new QLabel("Label with a proper (transparent) background"));
          layout->addWidget(new QLabel("<b>HTML</b> label with an <i>improper</i> (inherited from parent) background"));
      }
      
      // Gradient Widget:
      
      class GradientWidget : public QWidget {
      protected:
          void paintEvent(QPaintEvent *event)
          {
              QLinearGradient gradient(event->rect().topLeft(), event->rect().bottomRight());
              gradient.setColorAt(0, Qt::white);
              gradient.setColorAt(1, Qt::darkYellow);
              QPainter painter(this);
              painter.fillRect(event->rect(), gradient);
          }
      };
      

      Attachments

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            kefir500 Alexander Gorishnyak
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: