Results 1 to 6 of 6

Thread: Using StretchDIBits() in QWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    19
    Thanks
    12

    Default Re: Using StretchDIBits() in QWidget

    Ah, I found the solution on page 417 in the QT book. It will work using something like this:
    Qt Code:
    1. void MyWidget::paintEvent(QPaintEvent *p)
    2. {
    3. QPainter painter(this);
    4. HWND hWnd = winId();
    5. HDC hdc = painter.paintEngine()->getDC();
    6. RECT r;
    7. r.left = this->rect().left()+50;
    8. r.top = this->rect().top()+50;
    9. r.right = this->rect().right();
    10. r.bottom = this->rect().bottom();
    11. int xx = ::DrawText(hdc, L"FOOOOOOOOOO", 5, &r, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
    12. painter.paintEngine()->releaseDC(hdc);
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using StretchDIBits() in QWidget

    Be aware this is not safe without proper preparations. Your paintEvent will be called to draw something to the backing store so you have to prevent that by using PaintOnScreen. And your application will behave slower, by the way but if you really need a DC context then there is no way to avoid that. You can obtain the same effect using Qt only calls without any downsides.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    bear101 (5th May 2009)

Similar Threads

  1. QtScript Binding problem with QWidget
    By zack in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 09:38
  2. Replies: 0
    Last Post: 11th November 2008, 15:36
  3. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  4. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05
  5. Replies: 3
    Last Post: 8th March 2007, 14:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.