PDA

View Full Version : Changing painter settings for QPixmap



spagatoni
22nd October 2008, 01:56
I keep getting an unhandled exception when I do the following:

QPixmap p;

p = new QPixMap(600, 2500);

// crashes out on the set...will also crash out on anything tied to the painter.
p->paintEngine()->painter()->setPen(Qt::blue);

I figure I am doing a horribly novice mistake here so any help would be awesome.

Thanks for your time,
Jon Jones

JimDaniel
22nd October 2008, 02:49
What are you trying to do? I've never seen someone access the paintEngine directly like that, I'm not sure you're allowed.

spagatoni
22nd October 2008, 03:16
I am reading in a large set of data and using QwtPlot to render the data. Due to the way the data is coming in I want to plot the points to a QPixmap and then render them to the screen.

I can get the system to render the points to the Pixmap by doing:

p->paintEngine()->drawPoints(...);

but I need to render each of the points in a certain color based on a value from the data. that is why I attempt to set the pen with:

p->paintEngine()->painter()->setPen(...);

I hope I cleared that up. If not let me know.

Thanks for the quick reply,
Jon Jones

JimDaniel
22nd October 2008, 04:19
As for your current error, I'm not sure. I've never done it this way. Its possible someone else may be able to help further. The fact that you have to go through so many calls to get to the painter object throws up flags for me.

From what you've described, it seems more correct to instantiate a QPainter and pass into its constructor the pixmap as the paint device, and then do your painting. I could be wrong though.

Uwe
22nd October 2008, 12:26
I am reading in a large set of data and using QwtPlot to render the data. Due to the way the data is coming in I want to plot the points to a QPixmap and then render them to the screen.
Painting a curve ( or any other plot item ) to a pixmap and painting it instead will erase all other plot items (beside the pixmap has a transparent background), that are below the curve ( f.e. the grid ).

If your intention is, that you don't want to have all your data in memory at once, better derive from QwtData. The Qwt framework always iterates over the data object in increasing order, so you can load/discard your data in pieces.
Otherwise write your intention. I'm pretty sure the best solution will be different from what you have in mind.

Uwe

spagatoni
22nd October 2008, 15:32
From what you've described, it seems more correct to instantiate a QPainter and pass into its constructor the pixmap as the paint device, and then do your painting. I could be wrong though.

This may be a silly question but exactly what do you mean? This is a quick snippet of what I thought you meant:

QPixmap _pixMap = QPixmap::grabWidget(widget);

// Is this what you intend? Cause this crashes the system
QPainter *pixMapPainter = new QPainter(_pixMap.paintEngine()->paintDevice());

pixMapPainter->setPen(...);
pixMapPainter->drawPoint(x,y);

Thanks,
Jon Jones

spagatoni
22nd October 2008, 16:15
After looking around I at least figured out what you meant by instantiate the QPainter by using the QPixmap but now it isn't drawing anything to the pixmap.

The following is what I do for rendering to the pixmap...I think I am missing something..not sure what though:



QPainter pixMapPainter(&pixMap);
pixMapPainter.setPen(Qt::red);
pixMapPainter.drawPoint(x, y);


Thanks for the help,
Jon Jones

spagatoni
22nd October 2008, 16:41
After looking around I at least figured out what you meant by instantiate the QPainter by using the QPixmap but now it isn't drawing anything to the pixmap.

The following is what I do for rendering to the pixmap...I think I am missing something..not sure what though:



QPainter pixMapPainter(&pixMap);
pixMapPainter.setPen(Qt::red);
pixMapPainter.drawPoint(x, y);


Thanks for the help,
Jon Jones


Actually the above code does work. I had an issue elsewhere in the system so it functions correctly now!

Thanks for all the help and the pushes in the right direction I appreciate it greatly JimDaniel and Uwe!

Thanks,
Jon Jones