Hi All,
How to call a paint event function in key press event can anybody help me with the code snippet.
Regards,
soumya
Printable View
Hi All,
How to call a paint event function in key press event can anybody help me with the code snippet.
Regards,
soumya
You just need to call repaint() or update() function within keyPressEven().
Qt suggests to call update() to avoid slowdown and flickering.
Call update like this:
Code:
update();
EDIT:
Oops... i was late :P
Hi thanks for the reply i tried with update function but i am getting error as ,
circleform.cpp: In function ‘void update()’:
circleform.cpp:423: error: invalid use of ‘this’ in non-member function
and here is the code snippet
void circleForm::keyPressEvent( QKeyEvent *event )
{
switch ( event->key() )
{
case Qt::Ke_Enter:
update();
break;
}
}
void update(){
QPainter painter(this); // error
painter.setPen(QPen(Qt::black, 3,Qt::SolidLine));
painter.drawEllipse(100, 140, 160 , 160);
}
Regards,
Soumya
Hi,
I need to draw a circle on the frame which is at the top left corner as shown in the attachment. User can enter certain inputs
and when the user press the enter key the circle should be drawn on the frame any suggestions
Inherit the frame and draw using QPainter