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

QTextEdit doesn't respect transparency of textBackgroundColor in toHtml() method

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 4.7.3
    • None
    • Linux 2.6.x and 3.0.x, X Server 1.9.2
    • b8b3c9410ab99191d7085fc6815e9a7814e24352

    Description

      QTextEdit ignores transparency of textBackgroundColor when exporting rich text with toHtml() method (test program is attached). The most significant result of it is that if one set textBackgroundColor to Qt::transparent (as it's done in Plasma::TextEdit in KDE4, for example) and then enter some text to QTextEdit, cut/copy it and paste it back immediately, the text would be rendered on black background (color part of Qt::transparent) and is literally invisible.

      To reproduce:
      1. Create a form with QTextEdit and set textBackgroundColor of it to Qt::transparent.
      2. After form is painted set some text to QTextEdit.
      3. Throw output of QTextEdit::toHtml() and mention that background-color style property is #000000 and there's no opacity style property.

      Here's a small code snippet:

      #include <QDebug>
      
      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      
      MainWindow::MainWindow(QWidget *parent) :
      	QMainWindow(parent),
      	ui(new Ui::MainWindow)
      {
      	ui->setupUi(this);
      	ui->textEdit->setTextBackgroundColor(Qt::transparent);
      }
      
      MainWindow::~MainWindow()
      {
      	delete ui;
      }
      
      void MainWindow::on_pushButton_clicked()
      {
      	ui->textEdit->setText("this is test text");
      	qDebug() << "QTextEdit::toHtml():" << ui->textEdit->toHtml();
      }
      

      The result printed to console is:

      QTextEdit::toHtml(): "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
      <html><head><meta name="qrichtext" content="1" /><style type="text/css">
      p, li { white-space: pre-wrap; }
      </style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;">
      <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" background-color:#000000;">this is test text</span></p></body></html>"
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            achernov Alexey Chernov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes