Important: Please read the Qt Code of Conduct -

Some problems with drawLine function

  • Hi~ o( ̄▽ ̄)ブ,we are the undergraduates from china and we use Qt to do something about UWB. But now we meet some problems in developing a function to draw a Geo-fencing. We use the drawline-function to draw a line between the two points, but it seems a little bit strange when it finished. The line can't arrive another point (#°Д°),it really astonish us. We did a lot to research this problem, but we got nothing ( ̄_ ̄|||). Emmm, so we decide to ask for helps from the Qt Forum. We would appreciate a lot if someone give out some useful adviceヾ(≧▽≦*)o. (Please ignore our poor English)

  • Lifetime Qt Champion

    @Shagohod2000 Please show how you're drawing (show the code)

  • @jsulm
    void GraphicsView::drawFence(QPainter *painter)
    painter->drawLine(RTLSDisplayApplication::viewSettings()->setUpperLeftValueX(), RTLSDisplayApplication::viewSettings()->setUpperLeftValueY(), RTLSDisplayApplication::viewSettings()->setUpperRightValueX(), RTLSDisplayApplication::viewSettings()->setUpperRightValueY());
    painter->drawLine(RTLSDisplayApplication::viewSettings()->setUpperLeftValueX(), RTLSDisplayApplication::viewSettings()->setUpperLeftValueY(), RTLSDisplayApplication::viewSettings()->setLowerLeftValueX(), RTLSDisplayApplication::viewSettings()->setLowerLeftValueY());
    painter->drawLine(RTLSDisplayApplication::viewSettings()->setLowerLeftValueX(), RTLSDisplayApplication::viewSettings()->setLowerLeftValueY(), RTLSDisplayApplication::viewSettings()->setLowerRightValueX(), RTLSDisplayApplication::viewSettings()->setLowerRightValueY());
    painter->drawLine(RTLSDisplayApplication::viewSettings()->setLowerRightValueX(), RTLSDisplayApplication::viewSettings()->setLowerRightValueY(), RTLSDisplayApplication::viewSettings()->setUpperRightValueX(), RTLSDisplayApplication::viewSettings()->setUpperRightValueY());

    we use the void QPainter::drawLine(int x1, int y1, int x2, int y2) to do it

  • Qt false.PNG This is the wrong state
    Qt right.PNG This is the right state
    We just draw the fence across the four points

  • Lifetime Qt Champion

    @Shagohod2000 said in Some problems with drawLine function:


    What do these set* methods do? Why are they called set*? Set is usually used to set some value, not to get it.
    Back to your problem: check your coordinates - are those as expected?

  • @jsulm The primary cause of our error is the misuse of the integer parameter rather than float parameter in the drawling function. Sorry to reply so late and we really appreciate a lot for your help.

Log in to reply