Important: Please read the Qt Code of Conduct -

How to get DC from QPainter in windows?

  • I have a very very strange question, it is very urgent, hope anybody can help me!

    I want to get a native DC from QPainter. I tried like this:
    QPaintEngine* pe = painter.paintEngine();
    HDC dc = pe->getDC();

    This works fine if this painter is from a widget, like:
    QPainter painter(this); //"this" is widget
    But my painter is from a QPixmap:
    QPixmap pix(w, h);
    QPainter painter(&pix);

    This always fails!!! The DC in paintEngine() is always 0!

    Can anybody help me?


Log in to reply