Re: Problem with QPainter
As far as i know QPainter can paint on widgets only within paintevent, something like this:
Code:
//your painting code goes here
}
link to reference
Re: Problem with QPainter
I tried your suggestion by making a function in my class Waveform which has a member function device (ptr. to a QPushButton object) and i called this function from my MainWindow's constructors with no parameters.I got same problem once again i.e. application output showed the statement
QPainter::begin: Paint device returned engine == 0, type: 1
and begin function is returning false.
Here is the code of the public member function paintEvent that i made in my class WaveForm
void WaveForm:: paintEvent(QPaintEvent * event=0)
{
QLine line( 0, height() / 2.0, width(), height() / 2.0 );
QPen pen( Qt::blue, 10 ); // red solid line, 1 pixels wide
QPainter *painter=new QPainter();
if(!painter->begin(device))
qDebug()<<"Painter failed to begin";
painter->drawLine(line);
}
Please HELP!!
Re: Problem with QPainter
You didn't understood me, the QPainter can paint to a widget from it's own paintEvent (so use that code in the paintEvent of widget you are trying to paint <your "device" paintEvent> not in your mainWindow)
LE: You will call: painter->begin(this); //the pointer to the object itself