QPainter backgroundMode bug

Discuss anything related to product development
Post Reply
seasoned_geek
Posts: 208
Joined: Thu Jun 11 2020 12:18 pm

QPainter backgroundMode bug

Post by seasoned_geek »

I just spent 3 days slamming head viciously against keyboard identifying this. There appears to be some kind of Queued event lag with setting background mode.

Code: Select all

void SurfaceImpl::DrawTextNoClip( PRectangle rc,
                                  const Font *font,
                                  XYPOSITION ybase,
                                  std::string_view text,
                                  ColourRGBA fore,
                                  ColourRGBA back )
{
    Q_UNUSED( ybase )
    SetFont( font );
    PenColour( fore );

    GetPainter()->setBackground( QColorFromColourRGBA( back ) );
    GetPainter()->setBackgroundMode( Qt::OpaqueMode );
    QString su = UnicodeFromText( codec, text );
    GetPainter()->drawText( QPointF( rc.left, ybase ), su );
    //GetPainter()->drawText( QRectFFromPRect( rc ), su );

    // stop random background bleed over
    GetPainter()->setBackgroundMode( Qt::TransparentMode );

}
If that function is called and the final line setting mode back to transparent is not included

This method will "randomly" use the previous brush and background color

Code: Select all

void SurfaceImpl::DrawTextTransparent( PRectangle rc,
                                       const Font *font,
                                       XYPOSITION ybase,
                                       std::string_view text,
                                       ColourRGBA fore )
{
    GetPainter()->setBrush( Qt::NoBrush );
    SetFont( font );
    PenColour( fore );
    GetPainter()->setBackgroundMode( Qt::TransparentMode );
    QString su = UnicodeFromText( codec, text );
    GetPainter()->drawText( QPointF( rc.left, ybase ), su );
}
Despite the fact I deliberately force NoBrush and force the background mode to transparent. Just for completeness.

Code: Select all

QPainter *SurfaceImpl::GetPainter()
{
    Q_ASSERT( device );

    if ( !painter )
    {
        if ( device->paintingActive() )
        {
            painter = device->paintEngine()->painter();
        }
        else
        {
            painterOwned = true;
            painter = new QPainter( device );
        }

        // Set text antialiasing unconditionally.
        // The font's style strategy will override.
        painter->setRenderHint( QPainter::TextAntialiasing, true );

        painter->setRenderHint( QPainter::Antialiasing, true );
    }

    return painter;
}

This problem only occurs __after__ a newPage() call. It does not happen after every newPage() call. It does seem to persist for that entire page though.

https://www.logikalsolutions.com/wordpress/wp-content/uploads/2022/11/scintilla-prev-1-1.png

Sometimes multiple pages in a row, other times just one page and then fine again for many pages. Seems to happen more often after a break caused by FF in file.

It's seems like, once you have turned on Opaque, going back to transparent and throwing away the brush is merely a suggestion. :?

OH!

This only happens when the paint device is the widget inside of the QPrintPreviewDialog. Physically printed to printer and physically displayed to a primary widget all is well. This problem may be caused by or in QPrintPreviewWidget.

Post Reply