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?
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?