Results 1 to 5 of 5

Thread: Using of a custom QPaintEngine

  1. #1

    Default Using of a custom QPaintEngine

    Hi there,
    first I have to say sorry for my english.

    I' ve got this problem:
    I want to change the "drawPixmap(..)" methode. I've red in the Qt-Assistant there is the class QPaintEngine, wich is pure virtual. So I must reimplement this class. I've done it. Here is the code:
    the header.
    Qt Code:
    1. class MyPaintEngine : public QPaintEngine
    2. {
    3. //Q_OBJECT
    4.  
    5. private:
    6. HDC mHDC;
    7.  
    8. public:
    9. MyPaintEngine(PaintEngineFeatures caps = 0);
    10. ~MyPaintEngine();
    11.  
    12. bool begin(QPaintDevice* pdev);
    13. void setHDC(const HDC& hDC);
    14. void drawPixmap(const QRectF& r,const QPixmap& pm, const QRectF& sr );
    15. bool end();
    16. QPaintEngine::Type type() const;
    17. void updateState(const QPaintEngineState& state );
    18. void drawPolygon ( const QPoint * points, int pointCount, PolygonDrawMode mode );
    19. };
    To copy to clipboard, switch view to plain text mode 

    the cpp.
    Qt Code:
    1. void MyPaintEngine::drawPixmap(const QRectF& r,const QPixmap& pm, const QRectF& sr )
    2. {
    3. const unsigned int width(300),height(300);
    4. unsigned char* pixelBuffer = new unsigned char[height*width*4];
    5. unsigned int ii(0);
    6. for(int xx(0); xx<width; ++xx)
    7. {
    8. for(int yy(0); yy<height; ++yy)
    9. {
    10. pixelBuffer[ii] = 255;
    11. ++ii;
    12. pixelBuffer[ii] = 0;
    13. ++ii;
    14. pixelBuffer[ii] = 0;
    15. ++ii;
    16. pixelBuffer[ii] = 0;
    17. ++ii;
    18. }
    19. }
    20. BITMAP bmp;
    21. HDC hDCBmp(CreateCompatibleDC(mHDC)); // mHDC is a member which I set before i call this methode
    22. DWORD error(GetLastError());
    23. HBITMAP hBitmap(CreateCompatibleBitmap(mHDC,width,height));
    24. SelectObject (hDCBmp, hBitmap) ;
    25. SetBitmapBits(hBitmap,width*height*4,pixelBuffer);
    26.  
    27.  
    28. BitBlt(mHDC,(int)(100),(int)(100), 300,300, hDCBmp, 0,0, SRCCOPY);
    29. }
    To copy to clipboard, switch view to plain text mode 

    But this doesn't work. I only get my window in the default color.
    I choose this as an example, only drawing a blue rect.

    Why it doesn't work?
    What I have to do?
    Can anybody help my please?

  2. #2
    Join Date
    Sep 2006
    Posts
    19
    Thanks
    12

    Default Re: Using of a custom QPaintEngine

    Looks fine but how do you call your MyPaintEngine?

  3. #3

    Default Re: Using of a custom QPaintEngine

    I use this class as a pointer in MyChildWindow-class.
    There is a virtual function
    Qt Code:
    1. QPaintEngine* MyChildWindow::paintEngine() const
    2. {
    3. return mPaintEngine; // MyPaintEngine* mPaintEngine=new MyPaintEngine();
    4. }
    To copy to clipboard, switch view to plain text mode 

    When i debug, VC++ steps in my "drawPixmap" method.
    But nothing happens......

  4. #4
    Join Date
    Sep 2006
    Posts
    19
    Thanks
    12

    Default Re: Using of a custom QPaintEngine

    I think the problem lies in the way Windows draws. You should probably use the HDC which Qt provides. Get it by calling MyPaintEngine::getDC(). Remember to release it again.

    -- Bjoern

  5. #5

    Default Re: Using of a custom QPaintEngine

    Okay, I've done this. I used the "getDC()" of my MyPainterEngine-Class, but nothing happens.
    The result of the "getDC()" is NULL (?!?!?!) in my "drawPixmap"-function.

    *AAARRRGGGHHH*

Similar Threads

  1. Replies: 12
    Last Post: 5th July 2009, 16:03
  2. Replies: 2
    Last Post: 16th May 2008, 14:39
  3. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  4. Custom proxy model issue
    By Khal Drogo in forum Qt Programming
    Replies: 13
    Last Post: 30th November 2007, 12:41
  5. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.