Results 1 to 11 of 11

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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.