PDA

View Full Version : How to add lines to desired frame only



athulms
16th August 2011, 06:20
I an developing a game with three frame 1.mainframe 2.gameframe 3.letterframe.
How can i draw line for the letterframe only.?? for all other frames the Qpainter should be disabled
waiting for rply. Thanks in advance

athulms
16th August 2011, 08:43
i created a separate class for that particular area.
but i cant add more than 1line. when i start to draw the second line the first line disappears

void MainWindow::mousePressEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)
{
point = e->pos();
int tempx=point.rx();
tempx=tempx/50;
tempx=(tempx*50)+25;
int tempy=point.ry();
tempy=tempy/40;
tempy=(tempy*40)+20;
point.setX(tempx);
point.setY(tempy);
if(k==0)
{
point2=point;
k=1;
update();
return;
}
if(k==1)
k=0;
update();
}
}
void MainWindow::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
QPen linepen(Qt::red);
linepen.setWidth(30);
linepen.setCapStyle(Qt::RoundCap);
painter.setRenderHint(QPainter::Antialiasing,true) ;
painter.setPen(linepen);
if(k==1)
painter.drawPoint(point);
else
painter.drawLine(point,point2);
}