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. How can i use QPainter to draw triangles
Forum Updated to NodeBB v4.3 + New Features

How can i use QPainter to draw triangles

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 753 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.
  • B Offline
    B Offline
    BlackRagnor
    wrote on last edited by
    #1

    Hi,

    I'm new to Qt.
    Currently, i'm writing code that helps to compute any of the pythagorean triples (that is, any of hypotenuse, opposite, and adjacent). I use QDoubleSpinBox(es) to take the user's given values and compute the value not given. For instance, if the user enters the lengths of the opposite and adjacent sides, the program computes the hypotenuse.
    I want this program to be able to draw the right triangle anytime the computation is done.
    To achieve this, i'm using QPainter to draw the polygon (that is, the right triangle) in a paintEvent.

    The problem i have is that the painter retains the initial triangle drawn, and each time i click the 'submit' button (which calls the update() function in QPainter), it just keeps drawing the same triangle even if i enter different hypotenuse, opposite, and hypotenuse values.

    Please what can i do?

    jsulmJ 1 Reply Last reply
    0
    • B BlackRagnor

      Hi,

      I'm new to Qt.
      Currently, i'm writing code that helps to compute any of the pythagorean triples (that is, any of hypotenuse, opposite, and adjacent). I use QDoubleSpinBox(es) to take the user's given values and compute the value not given. For instance, if the user enters the lengths of the opposite and adjacent sides, the program computes the hypotenuse.
      I want this program to be able to draw the right triangle anytime the computation is done.
      To achieve this, i'm using QPainter to draw the polygon (that is, the right triangle) in a paintEvent.

      The problem i have is that the painter retains the initial triangle drawn, and each time i click the 'submit' button (which calls the update() function in QPainter), it just keeps drawing the same triangle even if i enter different hypotenuse, opposite, and hypotenuse values.

      Please what can i do?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @BlackRagnor said in How can i use QPainter to draw triangles:

      Please what can i do?

      You can show your code, so others can see what might be wrong

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

      B 1 Reply Last reply
      0
      • nageshN Offline
        nageshN Offline
        nagesh
        wrote on last edited by
        #3

        @BlackRagnor said in How can i use QPainter to draw triangles:

        different hypotenuse, opposite, and hypotenuse values.

        Does this different hypotenuse, opposite values are accessible in paintEvent ?

        1 Reply Last reply
        0
        • jsulmJ jsulm

          @BlackRagnor said in How can i use QPainter to draw triangles:

          Please what can i do?

          You can show your code, so others can see what might be wrong

          B Offline
          B Offline
          BlackRagnor
          wrote on last edited by
          #4

          @jsulm Thanks. I have fixed it.
          I deleted 'static' from the declaration of my QPointF array. So, rather than have:
          static const QPointF points [3] = { ... } ,
          I have:
          const QPointF points [3] = { ...}.
          Thanks everyone.

          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