Hi All,
How to call a paint event function in key press event can anybody help me with the code snippet.
Regards,
soumya
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:
EDIT:
Oops... i was late :P
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
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
soumya (3rd February 2010)
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
Bookmarks