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. Unreliable or bad behavior QTextBrowser rendering
Qt 6.11 is out! See what's new in the release blog

Unreliable or bad behavior QTextBrowser rendering

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 924 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.
  • J Offline
    J Offline
    Jirka
    wrote on last edited by
    #1

    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;
    

    }
    @

    1 Reply Last reply
    0

    • Login

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