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. Weird drawPath problem

Weird drawPath problem

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 685 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.
  • L Offline
    L Offline
    Landolfi
    wrote on last edited by
    #1

    So I have this problem: I designed a gauge that works almost always. In some environments the indicator is not shown. In the picture, the top gauge is correct, the bottom is wrong.

    I attach the code that draws the indicator (needle).

    In debug mode is working (of course...). In release, sometimes works, other times does not. Even in the same window, as in the picture.

    Changing execution mode to Win 7 compatibility makes it work.
    Executing with admin privilege makes it work.

    0_1559731304505_2b8d7a04-54e0-4f30-9911-d6d4de196c92-image.png ![alt text](image url)

    void Gauge::drawNeedleShort (QColor color)
    {
        QPainter p(this);
        p.setRenderHint(QPainter::Antialiasing);
    
        const float nedR = (extR+intR)/2;
        const float nR = intR*0.9;
        const float ncA = 4;
    
        QPainterPath needle;
        needle.moveTo(cX+nedR*cosfD(mAngle),cY-nedR*sinfD(mAngle));
    
        needle.lineTo(cX+nR*cosfD(mAngle+ncA),cY-nR*sinfD(mAngle+ncA));
        needle.arcTo(cX-nR,cY-nR,2*nR,2*nR,mAngle+ncA,-2*ncA);
        needle.closeSubpath();
    
        p.setPen(color);
        p.setBrush(QBrush(color));
        p.drawPath(needle);
    }
    
    1 Reply Last reply
    0
    • L Offline
      L Offline
      Landolfi
      wrote on last edited by
      #5

      Comes out there was an uninitialized variable that prevent drawing. It seems that IDE always initializes memory with some value.

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

        How do you call drawNeedleShort()? Hopefully only within the paintEvent().

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        L 1 Reply Last reply
        0
        • L Offline
          L Offline
          Landolfi
          wrote on last edited by
          #3
          This post is deleted!
          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            How do you call drawNeedleShort()? Hopefully only within the paintEvent().

            L Offline
            L Offline
            Landolfi
            wrote on last edited by
            #4

            @Christian-Ehrlicher said in Weird drawPath problem:

            How do you call drawNeedleShort()? Hopefully only within the paintEvent().

            Exactly, here it is the paintEvent. As you can note also the drawRange is not working in the bottom picture: the green sector below the indicator is not shown. drawQuadrant and drawTicks seem work every time.

            void Gauge::paintEvent(QPaintEvent *event)
            {
                drawQuadrant();
                QColor drawColor=QWidget::palette().color(QWidget::foregroundRole());
                drawRange();
                drawNeedleShort(drawColor);
                drawTicks();
            }
            
            
            1 Reply Last reply
            0
            • L Offline
              L Offline
              Landolfi
              wrote on last edited by
              #5

              Comes out there was an uninitialized variable that prevent drawing. It seems that IDE always initializes memory with some value.

              SGaistS 1 Reply Last reply
              0
              • L Landolfi

                Comes out there was an uninitialized variable that prevent drawing. It seems that IDE always initializes memory with some value.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Landolfi said in Weird drawPath problem:

                Comes out there was an uninitialized variable that prevent drawing. It seems that IDE always initializes memory with some value.

                Hi,

                No, the IDE as nothing to do with that. If you don't explicitly initialize your variables with a value, they will contain garbage that may or may not have any sense.

                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

                • Login

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