Results 1 to 11 of 11

Thread: To set focus on circumference circles when key is pressed

  1. #1
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default To set focus on circumference circles when key is pressed

    Hi All,

    When key is pressed i need to get a focus on smaller circles which is on the circumference of big circle as shown in the attachment .When i press F11 key it should rotate in anticlockwise directions form right hole to next hole similarly if i press F10 key it should rotate in clockwise direction form right hole to previous hole. I have written the code for it its entering the particular function i am getting the debug message on the console but its not getting focused on smaller circles.

    Here is the .cpp code as shown below,

    Qt Code:
    1. void circleForm::keyPressEvent( QKeyEvent *event )
    2. {
    3. // qDebug( "Key Press Event" );
    4. switch ( event->key() )
    5. {
    6. case Qt::Key_F11:
    7. nextBoltHoleCircle = TRUE;
    8. break;
    9. case Qt::Key_F10:
    10. prevBoltHoleCircle = TRUE;
    11. break;
    12. case Qt::Key_Enter:
    13. needToDrawCircle = TRUE;
    14. break;
    15. default:
    16. QWidget::keyPressEvent(event);
    17. }
    18. }
    19.  
    20.  
    21. void circleForm::PaintEvent(QPaintEvent *event){
    22. QDialog::PaintEvent(event);
    23. if(needToDrawCircle){
    24. QPainter painter(this);
    25. painter.setPen(QPen(Qt::blue, 1, Qt::DashDotDotLine));
    26. painter.drawLine(0,180,380,180);//horizontal line
    27. painter.drawLine(190,0,190,360);//vertical line
    28. painter.setPen(QPen(Qt::black, 2, Qt::SolidLine));
    29.  
    30. int framecentre_x = 190;
    31. int framecentre_y = 180;
    32. painter.drawPoint(framecentre_x,framecentre_y);//centrepoint
    33. painter.drawEllipse(framecentre_x-100,framecentre_y-100,200,200);//big circle(90,80)
    34. int i;
    35. double x;
    36. angle = 360.00/Hol;
    37. for(i = 0;i < Hol;i++ ){
    38. x = (angle * i);
    39. qDebug(" x = %lf\n",x);
    40. xangle = (x * PI)/180;
    41. qDebug("xangle = %lf",xangle);
    42. xcordinate = cosine(xangle);
    43. qDebug("xcordinate = %lf",xcordinate);
    44. yangle = (x * PI)/180;
    45. qDebug("yangle = %lf",yangle);
    46. ycordinate = sine(yangle);
    47. qDebug("ycordinate = %lf",ycordinate);
    48. painter.setPen(QPen(Qt::black, 2, Qt::SolidLine));
    49. painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);//working
    50. }
    51. painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
    52. painter.drawEllipse((190 + 100 * 1)- 10,(180 + 100 * 0)- 10,20,20);
    53.  
    54. }
    55. needToDrawCircle = FALSE;
    56.  
    57. if(prevBoltHoleCircle){
    58. QPainter painter(this);
    59. qDebug("painting bolt hole circle\n");
    60. qDebug("xcordinate = %lf",xcordinate);
    61. qDebug("ycordinate = %lf",ycordinate);
    62. painter.setBrush(QBrush(Qt::blue, Qt::SolidPattern));
    63. painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
    64. qDebug("PREVIOUS\n");
    65.  
    66. }
    67. prevBoltHoleCircle = FALSE;
    68. if(nextBoltHoleCircle){
    69. QPainter painter(this);
    70. qDebug("painting bolt hole circle\n");
    71. qDebug("xcordinate = %lf",xcordinate);
    72. qDebug("ycordinate = %lf",ycordinate);
    73. painter.setBrush(QBrush(Qt::blue, Qt::SolidPattern));
    74. painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
    75. qDebug("NEXT\n");
    76.  
    77. }
    78. nextBoltHoleCircle = FALSE;
    79. }
    To copy to clipboard, switch view to plain text mode 


    Sould i use signal slot mechanism ???..To draw a big circle on the frame i had used signal slot mechanism after entering the value in the lineEdit when i press enter key a circle should be drawn something like this which i have do now when i press F11 it should focus to next circle and if i press F10 it should focus to previous circle.Any help or suggestions

    Thanks in advance
    Soumya
    Attached Images Attached Images
    Last edited by wysota; 19th February 2010 at 11:07.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: To set focus on circumference circles when key is pressed

    First of all it is paintEvent() and not PaintEvent(). Second of all you can't assume the paint event fill only be called once after your key press event. You should keep a state of your instrument in the widget class (i.e. as the number of circle being considered as "focused") and update the state in your key press event. Then when the widget is redrawn it has to pickup the state and draw itself accordingly. The state has to be persistent and not volatile (i.e. you are not allowed to change any variables being part of the state in the paint event).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: To set focus on circumference circles when key is pressed

    Hello Sir,

    Thanks for the reply.Instead of using F10 and F11 if i use Key_Enter and Key_Return it works fine. The small circles which is on the circumference of big circle works fine and rotate in clockwise and antoclockwise direction when key is pressed but why not for F10 and F11?..Please give me some suggestions to proceed further

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: To set focus on circumference circles when key is pressed

    The keys may be intercepted globally by some other application (like the desktop or the system itself) but my remarks on the paint event still stand.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: To set focus on circumference circles when key is pressed

    t why not for F10 and F11?
    The first thing to test is to see if your application does indeed the get key events.
    Set a break point in your keyPressEvent(), and see if they are being caught.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: To set focus on circumference circles when key is pressed

    Thanks for everyone. Need to call update function now its working fine and below is the code snippet
    Qt Code:
    1. switch ( event->key() )
    2. {
    3. case Qt::Key_F11:
    4. nextBoltHoleCircle = TRUE;
    5. update();
    6. break;
    7. case Qt::Key_F10:
    8. prevBoltHoleCircle = TRUE;
    9. update();
    10. break;
    11. case Qt::Key_Enter:
    12. needToDrawCircle = TRUE;
    13. update();
    14. break;
    15. default:
    16. QWidget::keyPressEvent(event);
    17. }
    To copy to clipboard, switch view to plain text mode 

    Best Regards,
    Soumya
    Last edited by wysota; 23rd February 2010 at 15:01.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: To set focus on circumference circles when key is pressed

    Could you tell me if your program works properly if you press F10 or F11 and then start resizing the dialog?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: To set focus on circumference circles when key is pressed

    ya its working fine

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: To set focus on circumference circles when key is pressed

    With the paintEvent() you posted earlier? Or did you change it? Could you post the complete code of your widget here as an attachment?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: To set focus on circumference circles when key is pressed

    Hi,

    I have sent the entire code in the attachment it works fine

    Regards,
    Soumya
    Attached Files Attached Files
    Last edited by soumya; 26th February 2010 at 08:03.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: To set focus on circumference circles when key is pressed

    I'm afraid your application doesn't work on my system, I can't see any "holes" and you disabled resizing the dialog so I don't know how could you say that your application works when the dialog is resized The code is broken, believe me.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Performance problem with drawing circles
    By kamre in forum Qt Programming
    Replies: 4
    Last Post: 15th September 2009, 05:35
  2. Replies: 3
    Last Post: 17th March 2008, 19:54
  3. MenuBar grabs the focus on ALT pressed.
    By Cutey in forum Qt Tools
    Replies: 7
    Last Post: 16th January 2007, 09:59
  4. MenuBar grabs focus on ALT pressed.
    By Cutey in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2007, 11:45
  5. Adding numbers to circles in QPaint
    By therealjag in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2006, 10:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.