Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. What is the best way to do this?
Qt 6.11 is out! See what's new in the release blog

What is the best way to do this?

Scheduled Pinned Locked Moved Solved Qt 6
qt5 c++11painteevent
4 Posts 3 Posters 1.3k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    Christina123
    wrote on last edited by
    #1

    Hi, I want to create an interface that allows users to draw whatever they want but those infographics are composed of segments of lines. For example, if you want to draw a square then it will consist of 4 different lines. It is apparent that the lines should not disappear when the paintevent is triggered. Currently, I am using a vector array to store the start and end QPoint of a line. Is there a better and sophisticated way of doing the job?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      An other possible way is to use a QPainterPath. Or a collection of QLine.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Christina123
        wrote on last edited by
        #3

        Thank you for your reply. I've decided to use QPainterPath to achieve this. But, I am wondering how to set the initial point for the path as I want my starting point to be the position at which the mouse is pressed.

        jsulmJ 1 Reply Last reply
        0
        • C Christina123

          Thank you for your reply. I've decided to use QPainterPath to achieve this. But, I am wondering how to set the initial point for the path as I want my starting point to be the position at which the mouse is pressed.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Christina123 Use mousePressEvent, it provides the cursor position as parameter https://doc.qt.io/qt-5/qwidget.html#mousePressEvent

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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