Problem drawing an Arrow using RArrow class (solved)



  • error:: expected primary-expression before ')' token

    Not able to draw an Arrow using rarrow class link as below:
    https://rittwik.wordpress.com/2012/08/29/rarrow-class-for-drawing-arrows/

    MainWindow::MainWindow
    {
    RArrow *Rarrow = new RArrow();
    Rarrow-> raDrawArrow(QPainter);
    }
    raSetArrowHead use 3 raArrowsPoints[ ] to create Head
    raSetArrowLine use 4 raArrowsPoints[ ] to create Rectangle.

    Amend RArrow constructor as follow :
    RArrow::RArrow()
    { raStartPoint = QPoint(5,5);
    raEndPoint = QPoint(40,40);
    raLineWidth = 20;
    raHeadHeight = 5;
    raBorderThickness =2 ;
    for( int i=0;i<7;i++)
    raArrowPoints[i]=QPointF(-1,-1);
    }


  • Moderators

    @houmingc said:

    Rarrow-> raDrawArrow(QPainter);

    You need to pass a pointer to the QPainter object you want to paint with. So, for example, if you want to draw on a custom widget then reimplement its paintEvent method like this:

    void SimpleExampleWidget::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
        painter.setPen(Qt::blue);
        painter.setFont(QFont("Arial", 30));
        painter.drawText(rect(), Qt::AlignCenter, "Qt");
        // ...
        RArrow *Rarrow = new RArrow();
        Rarrow-> raDrawArrow(&painter);
    }
    


  • It work.
    Can please briefly explain why pass a pointer QPainter object to the paint Object

    ---- To draw 3 arrow -----
    QPainter painter(this);
    Rarrow1->setStart(QPointF(100,110));
    Rarrow1->setEnd(QPointF(150,110));
    Rarrow1->raDrawArrow(&painter);

    Rarrow1->setStart(QPointF(160,110));
    Rarrow1->setEnd(QPointF(200,110));
    Rarrow1->raDrawArrow(&painter);

    Rarrow1->setStart(QPointF(250,110));
    Rarrow1->setEnd(QPointF(300,110));
    Rarrow1->raDrawArrow(&painter);


  • Moderators

    Can please briefly explain why pass a pointer

    Because the website you linked to says so. :-) It says:

    After specifying these variables you can call the
    void raDrawArrow(QPainter *)
    function to draw the arrow using the QPainter.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.