Recurcive repaint problem
-
wrote on 24 Jun 2014, 20:38 last edited by
If it was so obvious, I wouldn't post this question.Just to correct this question, my error comes, when I click on any button. If you can see the code, there're no ways to compute geom.
-
wrote on 24 Jun 2014, 20:50 last edited by
Please describe a bit mor,when this occures.
At startup? After doing what? -
wrote on 24 Jun 2014, 20:58 last edited by
The app starts nicely, but when I try to press any button this stuff happens. If you want the app is on github you can download hole project there. I think the hole problem is mouseEvent and paintEvent, because f.e. rectButtonClicked, ellButtonClicked, lineButtonClicked is only assure, that only one button is active( checked ) at a time. And another methods are just for initialization.
-
wrote on 24 Jun 2014, 21:01 last edited by
Hi,
I just started the programin the debugger.
what fails is:@
void MyPaint::paintEvent(QPaintEvent *pe)
{
QPainter painter( this );
if( lineButClicked )
{
painter.drawLine( geom[index][0], geom[index][1] ); //<-- here
index++;
pointsNum = 0;
}
@geom has size 1, geom[0] has size 0, but you access elements of it.
you activate the sections inpaint with clicking the button. But the geom vector does contain an empty vector.
-
wrote on 24 Jun 2014, 21:03 last edited by
Okay, I just don't understand why it repaints , when I press the button.
-
wrote on 24 Jun 2014, 21:07 last edited by
But your code hasmor problems.
You are painting on the dialog, not on the view for example.@
void MyPaint::paintEvent(QPaintEvent *pe)
{
QPainter painter( this );
painter.setPen(Qt::red);
if( lineButClicked )
{
if(geom[index].size() >= 2)
{
painter.drawLine( geom[index][0], geom[index][1] );
index++;
pointsNum = 0;
}
}
else if( ellButClicked )
{
if(geom[index].size() >= 2)
{
painter.drawRect( QRect( geom[index][0], geom[index][1] ) );
index++;
pointsNum = 0;
}
}
else if ( rectButClicked )
{
if(geom[index].size() >= 2)
{
painter.drawEllipse( QRect( geom[index][0], geom[index][1] ) );
index++;
pointsNum = 0;
}
}
}@
-
wrote on 24 Jun 2014, 21:09 last edited by
[quote author="Vyivrain" date="1403643808"]Okay, I just don't understand why it repaints , when I press the button.[/quote]
it may repaint whenever it wants. Maybe due to the cursor change.
-
wrote on 24 Jun 2014, 21:13 last edited by
Yeah, I know, but I can't paint on the dialog, because I have a condition in mouseEvent. But the main thing is repaint. How ca I deal with it, so it will repaint only, when mouseEvent occurs and there I'll use update to launch paintEvent. And because I didn't know that repaint calls whenever it wants , it became obvious error, my bad =(.
-
wrote on 24 Jun 2014, 21:39 last edited by
Okay, did that with another if statement. But , I can paint on the just if I do QPainter( view ) correct? Nevermind, did that too.
-
wrote on 26 Jun 2014, 16:16 last edited by
You have to overwrite the paint event of the widget, where you want to paint in.
You subclassed the dialog, hence you draw in the dialog.@
void MyPaint::paintEvent(QPaintEvent *pe)
@MyPaint is the dialog...
[quote author="Vyivrain" date="1403644402"]Yeah, I know, but I can't paint on the dialog, because I have a condition in mouseEvent. But the main thing is repaint. How ca I deal with it, so it will repaint only, when mouseEvent occurs and there I'll use update to launch paintEvent. And because I didn't know that repaint calls whenever it wants , it became obvious error, my bad =(.[/quote]
Repaints can also occure, if yomeone puts a window in front of yours and away again, there are many reasons.
12/12