QT: Scroll widget that renders directly to the DC

I'm trying to create a widget which paints directly to the windows Device Context by calling getDC() and painting an HBITMAP to it. The widget I'm painting resides inside a scroll widget. I've implemented the paintEvent() and it does seem to paint but immediatly after painting the widget gets painted over again with a blank gray color.

I've tried setting WA_PaintOnScreen and Qt::WA_NoSystemBackground but none of those help. In theory this should be possible since this is basically how the GLWidget works.

What am I missing?


Found the answer here:


void GdiControl::paintEvent(QPaintEvent * /* event */)
    RECT rect;
    GetClientRect(winId(), &rect);
    HDC hdc = GetDC(winId());
    FillRect(hdc, &rect, HBRUSH(COLOR_WINDOW + 1));
    SetTextAlign(hdc, TA_CENTER | TA_BASELINE);
    TextOutW(hdc, width() / 2, height() / 2, text.utf16(), text.size());
    ReleaseDC(winId(), hdc);

For this to work, we must also reimplement QPaintDevice::paintEngine() to return a null pointer and set the Qt::WA_PaintOnScreen attribute in the widget's constructor.

Need Your Help

InterSystems Caché ODBC - max result length

c# intersystems-cache intersystems

I use ODBC for querying on InterSystems Caché db.

Connection per user

c# asp.net mysql

I'm using the code below, and what I want to do is use the same connection for the user throughout the time they are logged in. Now my understanding of using is it disposes of the connection, but ...