PDA

View Full Version : Using of a custom QPaintEngine



Jonas_
27th July 2009, 10:33
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.


class MyPaintEngine : public QPaintEngine
{
//Q_OBJECT

private:
HDC mHDC;

public:
MyPaintEngine(PaintEngineFeatures caps = 0);
~MyPaintEngine();

bool begin(QPaintDevice* pdev);
void setHDC(const HDC& hDC);
void drawPixmap(const QRectF& r,const QPixmap& pm, const QRectF& sr );
bool end();
QPaintEngine::Type type() const;
void updateState(const QPaintEngineState& state );
void drawPolygon ( const QPoint * points, int pointCount, PolygonDrawMode mode );
};


the cpp.


void MyPaintEngine::drawPixmap(const QRectF& r,const QPixmap& pm, const QRectF& sr )
{
const unsigned int width(300),height(300);
unsigned char* pixelBuffer = new unsigned char[height*width*4];
unsigned int ii(0);
for(int xx(0); xx<width; ++xx)
{
for(int yy(0); yy<height; ++yy)
{
pixelBuffer[ii] = 255;
++ii;
pixelBuffer[ii] = 0;
++ii;
pixelBuffer[ii] = 0;
++ii;
pixelBuffer[ii] = 0;
++ii;
}
}
BITMAP bmp;
HDC hDCBmp(CreateCompatibleDC(mHDC)); // mHDC is a member which I set before i call this methode
DWORD error(GetLastError());
HBITMAP hBitmap(CreateCompatibleBitmap(mHDC,width,height)) ;
SelectObject (hDCBmp, hBitmap) ;
SetBitmapBits(hBitmap,width*height*4,pixelBuffer);


BitBlt(mHDC,(int)(100),(int)(100), 300,300, hDCBmp, 0,0, SRCCOPY);
}


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?

bear101
27th July 2009, 13:44
Looks fine but how do you call your MyPaintEngine?

Jonas_
28th July 2009, 08:32
I use this class as a pointer in MyChildWindow-class.
There is a virtual function


QPaintEngine* MyChildWindow::paintEngine() const
{
return mPaintEngine; // MyPaintEngine* mPaintEngine=new MyPaintEngine();
}


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

bear101
28th July 2009, 08:48
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

Jonas_
28th July 2009, 09:08
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*