Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Line drawing using qpainter

    General and Desktop
    3
    6
    1709
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      deathholes last edited by

      After trying many things and failed, i finally came here to do what i was trying.
      I want to display lines which are stored in a file named "line.txt" in comma seperated values.
      i have successfully read the values, but unable to draw them on the screen.
      please help.

      1 Reply Last reply Reply Quote 0
      • Q
        QMartin last edited by

        Hi!

        You need to re-implement

        @void paintEvent(QPaintEvent *);@

        Inside it, create a QPainter. With it, call drawLine (look "here":https://qt-project.org/doc/qt-4.8/qpainter.html#drawLine). Hope this helps.

        Regards

        1 Reply Last reply Reply Quote 0
        • T
          tzander last edited by

          the method you likely want is the drawText().

          Notice that you may just want to use a QTextDocument, which has a paint method too.

          Or even higher level, use the QTextEdit widget.

          1 Reply Last reply Reply Quote 0
          • D
            deathholes last edited by

            [quote author="QMartin" date="1360425719"]Hi!

            You need to re-implement

            @void paintEvent(QPaintEvent *);@

            Inside it, create a QPainter. With it, call drawLine (look "here":https://qt-project.org/doc/qt-4.8/qpainter.html#drawLine). Hope this helps.

            Regards[/quote]

            i have tried it but somehow it is not working. It is working for a single line. but for drawing multiple lines it doesn't show them all.

            1 Reply Last reply Reply Quote 0
            • D
              deathholes last edited by

              [quote author="Thomas Zander" date="1360429277"]the method you likely want is the drawText().

              Notice that you may just want to use a QTextDocument, which has a paint method too.

              Or even higher level, use the QTextEdit widget.[/quote]

              I need to draw only lines and not text.
              anyway thanks for the help.

              1 Reply Last reply Reply Quote 0
              • D
                deathholes last edited by

                Ok , i tried again and succeeded this time.
                method used:
                read all the lines from the file into a qvector<qline> and used qpainter::drawlines() to draw the lines all at a time.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post