QT: scroll widget that displays directly in DC

I am trying to create a widget that draws directly in the Window Device Context, invoking getDC()and drawing on it HBITMAP.
The widget that I draw is inside the scroll widget.
I implemented paintEvent(), and it seems to draw, but immediately after painting the widget again turns blank gray.

I tried the installation WA_PaintOnScreenand Qt::WA_NoSystemBackgroundbut none of them helped.
Theoretically, this should be possible, since it basically works GLWidget.

What am I missing?

+3
source share
1 answer

Found the answer here:

http://www.qtchina.net/qt4c++guiprogramming/ch20lev1sec1.html/

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);
}

, QPaintDevice::paintEngine(), Qt::WA_PaintOnScreen .

+3

Source: https://habr.com/ru/post/1738082/


All Articles