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.
Code:
{
//Q_OBJECT
private:
HDC mHDC;
public:
MyPaintEngine(PaintEngineFeatures caps = 0);
~MyPaintEngine();
void setHDC(const HDC& hDC);
void drawPixmap(const QRectF& r,const QPixmap& pm, const QRectF& sr );
bool end();
void updateState(const QPaintEngineState& state );
void drawPolygon
( const QPoint * points,
int pointCount, PolygonDrawMode mode
);
};
the cpp.
Code:
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?
Re: Using of a custom QPaintEngine
Looks fine but how do you call your MyPaintEngine?
Re: Using of a custom QPaintEngine
I use this class as a pointer in MyChildWindow-class.
There is a virtual function
Code:
{
return mPaintEngine; // MyPaintEngine* mPaintEngine=new MyPaintEngine();
}
When i debug, VC++ steps in my "drawPixmap" method.
But nothing happens...... :confused: :mad: :crying:
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
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*