PDA

View Full Version : Why doesn't the line appear on my Image?



Gh0stR1der
18th April 2009, 04:13
Hi everybody out there using Qt4, I am doing a simple experiment using Qt4, I just wanna draw lines on a loaded image, here's the paintEvent code:


void GpsLocator::paintEvent(QPaintEvent *event){
image=new QImage();
image->load(*imageName);
windowPainter=new QPainter(this);
windowPainter->initFrom(this);
windowPainter->drawImage(0,0,*image);
this->setMinimumSize(image->width(),image->height());
imagePainter=new QPainter(image);
imagePainter->setPen(QPen(Qt::DotLine));
imagePainter->drawLine(218,223,433,375);
}

but this doesn't work, while the image is loaded successfully, but the line doesn't appear, I am just wondering how this could happen? Can anyone do me a favor, many thanks!

wysota
19th April 2009, 00:42
The code is all wrong. Do you by any chance come from the Java world? :) It looks you are used to having a garbage collector and allocating everything on the heap. Don't do that with QImage and QPainter. Furthermore don't put the code in paintEvent as it may be called without you knowing and it is crucial that it executes as fast as possible. Fix the errors and then we can continue.