Unreliable or bad behavior QTextBrowser rendering



  • Hello,

    In environment Windows 7, 64 bit, Qt 5.1.0 , QtCreator 2.7.2 I tried creating no transparent html text on background with parameterized transparency.

    Behavior rendering of QTextBrowser object was unexpected.

    With transparent background was an even different results under Mingw and MSVC2012.
    MSVC2012 produces semitransparent background and Mingw puts haphazardly diferent number of strange pixels into background.
    Have anybody any advice for me, please?

    Jirka

    Project:
    @
    TEMPLATE = app
    TARGET = demo
    QT += widgets
    SOURCES += demo.cpp
    @

    Code:
    @
    #include <QApplication>
    #include <QTextBrowser>

    int main(int argc , char ** argv )

    {
    QApplication a_oApp (argc, argv);

    for (int a_i = 0; a_i < 6; a_i++)
    {
       QString a_oS = "&lt;html&gt;&lt;body style=\"background-color: transparent\"><font color=\"red\" style=\"font-size: 28px; font-family: Arial\">--ahoj--</font>&lt;/body&gt;&lt;/html>";
    
       // create document from text and find out its size
       QTextDocument a_oTD;
       a_oTD.setHtml (a_oS);
       QSizeF a_oHtmlSz = a_oTD.size();
        
       // create text browser for document
       QTextBrowser a_oTB;
    
       #if 1
         // create transparent color
         QColor a_oCTransp (255, 255, 255);
         a_oCTransp.setAlpha (0);
    
         a_oTB.viewport()->setAutoFillBackground (false);
         QPalette a_oTBPal = a_oTB.palette();
         a_oTBPal.setColor(QPalette::Window, a_oCTransp);
         a_oTB.setPalette(a_oTBPal);
         a_oTB.setAttribute(Qt::WA_TranslucentBackground);
      #else // alternative
         a_oTB.viewport()->setAutoFillBackground (false);
         a_oTB.setAttribute(Qt::WA_TranslucentBackground);
      #endif
      a_oTB.setWindowFlags(Qt::FramelessWindowHint);
      //a_oTB.setAttribute(Qt::WA_NoBackground);
      a_oTB.setFrameStyle(QFrame::Plain);
      a_oTB.setLineWrapMode(QTextEdit::NoWrap);
    
      a_oTB.resize (a_oHtmlSz.width (), a_oHtmlSz.height ());
      #if 1
         a_oTB.setDocument(& a_oTD);
      #else // alternative
         a_oTB.setHtml(a_oS);
      #endif
    
      // grab a picture from text browser
      QPixmap a_oPM (a_oTB.size ());
    
      a_oTB.render (& a_oPM);
    
      QString a_oNPm = QString ("pixm_%1.bmp").arg (a_i);
      a_oPM.save (a_oNPm, "BMP");
    
    }  // for
    return 0;
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.