Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Line drawing using qpainter
QtWS25 Last Chance

Line drawing using qpainter

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.0k Views
  • 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 Offline
    D Offline
    deathholes
    wrote on last edited by
    #1

    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
    0
    • Q Offline
      Q Offline
      QMartin
      wrote on last edited by
      #2

      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
      0
      • T Offline
        T Offline
        tzander
        wrote on last edited by
        #3

        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
        0
        • D Offline
          D Offline
          deathholes
          wrote on last edited by
          #4

          [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
          0
          • D Offline
            D Offline
            deathholes
            wrote on last edited by
            #5

            [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
            0
            • D Offline
              D Offline
              deathholes
              wrote on last edited by
              #6

              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
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved