Results 1 to 5 of 5

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,

    [CODE]
    void circleForm::keyPressEvent( QKeyEvent *event )
    {
    // qDebug( "Key Press Event" );
    switch ( event->key() )
    {
    case Qt::Key_F11:
    nextBoltHoleCircle = TRUE;
    break;
    case Qt::Key_F10:
    prevBoltHoleCircle = TRUE;
    break;
    case Qt::Key_Enter:
    needToDrawCircle = TRUE;
    break;
    default:
    QWidget::keyPressEvent(event);
    }
    }


    void circleForm::PaintEvent(QPaintEvent *event){
    QDialog::PaintEvent(event);
    if(needToDrawCircle){
    QPainter painter(this);
    painter.setPen(QPen(Qt::blue, 1, Qt:ashDotDotLine));
    painter.drawLine(0,180,380,180);//horizontal line
    painter.drawLine(190,0,190,360);//vertical line
    painter.setPen(QPen(Qt::black, 2, Qt::SolidLine));

    int framecentre_x = 190;
    int framecentre_y = 180;
    painter.drawPoint(framecentre_x,framecentre_y);//centrepoint
    painter.drawEllipse(framecentre_x-100,framecentre_y-100,200,200);//big circle(90,80)
    int i;
    double x;
    angle = 360.00/Hol;
    for(i = 0;i < Hol;i++ ){
    x = (angle * i);
    qDebug(" x = %lf\n",x);
    xangle = (x * PI)/180;
    qDebug("xangle = %lf",xangle);
    xcordinate = cosine(xangle);
    qDebug("xcordinate = %lf",xcordinate);
    yangle = (x * PI)/180;
    qDebug("yangle = %lf",yangle);
    ycordinate = sine(yangle);
    qDebug("ycordinate = %lf",ycordinate);
    painter.setPen(QPen(Qt::black, 2, Qt::SolidLine));
    painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);//working
    }
    painter.setBrush(QBrush(Qt::red, Qt::SolidPattern));
    painter.drawEllipse((190 + 100 * 1)- 10,(180 + 100 * 0)- 10,20,20);

    }
    needToDrawCircle = FALSE;

    if(prevBoltHoleCircle){
    QPainter painter(this);
    qDebug("painting bolt hole circle\n");
    qDebug("xcordinate = %lf",xcordinate);
    qDebug("ycordinate = %lf",ycordinate);
    painter.setBrush(QBrush(Qt::blue, Qt::SolidPattern));
    painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
    qDebug("PREVIOUS\n");

    }
    prevBoltHoleCircle = FALSE;
    if(nextBoltHoleCircle){
    QPainter painter(this);
    qDebug("painting bolt hole circle\n");
    qDebug("xcordinate = %lf",xcordinate);
    qDebug("ycordinate = %lf",ycordinate);
    painter.setBrush(QBrush(Qt::blue, Qt::SolidPattern));
    painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
    qDebug("NEXT\n");

    }
    nextBoltHoleCircle = FALSE;
    }


    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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    I have a feeling that you should have used graphics view framework. It would have been easy with items.
    For your current approach, you will need to define a mechanism how to identify the circles and a lot of things.

  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

    Thanks for the reply. I just need to get the focus to the circle.I
    can identify the circle form its x and y coordinates and radius.
    Any suggestions so that i can do it using qpainter itself.


    Regards,
    soumya

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

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

    What do you mean by get focus to circle ? If you can identify a circle, you can draw it in a particular color to show it has got focus.

  5. #5
    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

    When key is pressed it should get focus
    painter.drawEllipse((190 + 100 * xcordinate)- 10,(180 + 100 * ycordinate)- 10,20,20);
    i know the xcordinate and ycordinate so it should draw at the particular circumference of big circle but some
    connections should be done right like how we done before

Similar Threads

  1. Replies: 10
    Last Post: 27th February 2010, 09:16
  2. Performance problem with drawing circles
    By kamre in forum Qt Programming
    Replies: 4
    Last Post: 15th September 2009, 05:35
  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.