Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can i use QPainter to draw triangles



  • 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?


  • Lifetime Qt Champion

    @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



  • @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 ?



  • @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.


Log in to reply