Results 1 to 3 of 3

Thread: Collision of a pushbutton with lines does not work???

  1. #1
    Join Date
    Jul 2012
    Posts
    24
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Collision of a pushbutton with lines does not work???

    Hi
    I want to detect the collision between the movin pushbutton with several lines drawn on the screen , here is the code that I use for this purpose but it does not work I don't know why , please guide me:

    (first of all I have changed the type of the lines of the pushbutton to QlineF inorder to be able to use intersection rules)

    QLineF line1 (ui->pushButton->x(),ui->pushButton->y(),ui->pushButton->x()+ui->pushButton->width(),ui->pushButton->y());
    QLineF line2 (ui->pushButton->x(),ui->pushButton->y(),ui->pushButton->x(),ui->pushButton->y()+ui->pushButton->height());
    QLineF line3 (ui->pushButton->x(),ui->pushButton->y()+ui->pushButton->height(),ui->pushButton->x()+ui->pushButton->width(),ui->pushButton->y()+ui->pushButton->height());
    QLineF line4 (ui->pushButton->x()+ui->pushButton->width(),ui->pushButton->y(),ui->pushButton->x()+ui->pushButton->width(),ui->pushButton->y()+ui->pushButton->height());

    //determining whether or not pushButton collides with lines or not
    QPointF* p1= new QPointF;
    QPointF* p2= new QPointF;
    QPointF* p3= new QPointF;
    QPointF* p4= new QPointF;
    int x1 = l1.intersect(line1,p1);
    int x2 = l1.intersect(line2,p2);
    int x3 = l2.intersect(line1,p3);
    int x4 = l2.intersect(line2,p4);


    if ( x1 == 1)
    {
    QMessageBox::StandardButton reply2;
    reply2 = QMessageBox::critical(this,"Error1" , " G " , QMessageBox::Close);
    ......................................
    }

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Collision of a pushbutton with lines does not work???

    I don't know why it does not work, but before asking people to try to understand it, you should write correct code. For example, the results of your QLineF::intersect() calls are captured in an integer, but the functions really return IntersectType
    IntersectType QLineF::intersect ( const QLineF & line, QPointF * intersectionPoint ) const

  3. The following user says thank you to mvuori for this useful post:

    mahsa (29th July 2012)

  4. #3
    Join Date
    Jul 2012
    Posts
    24
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Collision of a pushbutton with lines does not work???

    today I solved my problem myself so i will let the others know the solution
    for collision detection :
    define lines and pushbutton as QRectFs then use QRectF.intersects(&rect);
    and it will magically work)))

Similar Threads

  1. SetIcon ON for pushbutton does not work
    By tonnot in forum Newbie
    Replies: 6
    Last Post: 14th September 2011, 12:24
  2. Replies: 3
    Last Post: 29th April 2011, 08:54
  3. Collision between QGraphicsItem -
    By been_1990 in forum General Discussion
    Replies: 6
    Last Post: 19th November 2010, 12:32
  4. collision detection...
    By Muffin in forum Newbie
    Replies: 1
    Last Post: 8th January 2010, 10:28
  5. Collision handling 101
    By Morea in forum Qt Programming
    Replies: 9
    Last Post: 25th November 2006, 20:17

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.