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 top place a Image incide a custom dial without using Qml

How top place a Image incide a custom dial without using Qml

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 542 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.
  • J Offline
    J Offline
    Jaswenth S
    wrote on last edited by
    #1
    void DialWidget::drawImage(QPainter *painter)
    {
         QImage pix("J:/#Curneu/UI/Head Positioning/front.png");
         QRectF target(m_SIDE_LENGTH / 2, m_SIDE_LENGTH / 2,80,60);
         QRectF source(m_SIDE_LENGTH / 2, m_SIDE_LENGTH / 2,4.0,4.0);
         painter->save();
          painter->drawImage(target,pix,source);
         painter->restore();
    }
    

    So this is the function that i am using and I didn't get any errors but , I can't able to see the image at the center of the dial . Help me with this

    SGaistS 1 Reply Last reply
    0
    • J Jaswenth S

      @SGaist no I didn't check , how to check that the image is loaded.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #9

      @Jaswenth-S
      Hi
      You can check with
      https://doc.qt.io/qt-5/qpixmap.html#isNull
      if it was loaded.

      You are using an overload that also accepts a rect for source.
      Do you mean to only use some part of the image ?
      as else you can just draw it without the source and full image is used.
      https://doc.qt.io/qt-5/qpainter.html#drawImage-4
      this will also scale the image to the rest.
      So it the goal to fit the image to some rect or do you just want to draw the image as is ?

      J 1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #2

        Hi
        So in PaintEvent, you call drawImage before the normal paint for dial or how did
        Did you integrate it with the normal drawing ?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jaswenth S
          wrote on last edited by Jaswenth S
          #3
          void DialWidget::paintEvent(QPaintEvent *)
          {
            QPainter *painter = new QPainter(this);
          
            painter->setRenderHints(QPainter::Antialiasing, true);
          
            // Set the origin to the center of the dial widget
            painter->translate(m_SIDE_LENGTH / 2, m_SIDE_LENGTH / 2);
          
            drawFace(painter);
            drawTickMarks(painter);
            drawTitleAndUnitLabels(painter);
            drawValueLabels(painter);
            drawImage(painter);
          
            painter->end();
          }
          

          This is how I did

          First I tried using indicator needle at the center its working fine .. but when i try with an image it doesn't turn up

          mrjjM 1 Reply Last reply
          0
          • J Jaswenth S
            void DialWidget::paintEvent(QPaintEvent *)
            {
              QPainter *painter = new QPainter(this);
            
              painter->setRenderHints(QPainter::Antialiasing, true);
            
              // Set the origin to the center of the dial widget
              painter->translate(m_SIDE_LENGTH / 2, m_SIDE_LENGTH / 2);
            
              drawFace(painter);
              drawTickMarks(painter);
              drawTitleAndUnitLabels(painter);
              drawValueLabels(painter);
              drawImage(painter);
            
              painter->end();
            }
            

            This is how I did

            First I tried using indicator needle at the center its working fine .. but when i try with an image it doesn't turn up

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Jaswenth-S

            Ok. so it's a total custom dial.
            Could be the
            painter->translate
            You can test what by replace
            painter->drawImage(target,pix,source);
            with
            painter->drawRect(target);

            If path is surely valid, then it must be the rects.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jaswenth S
              wrote on last edited by
              #5

              okei I will try that and inform ....

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jaswenth S
                wrote on last edited by
                #6

                Now I can able to display a rectangle inside the dial ,, but when trying with an image its not coming even with the same target , I think it has some issue with the source when trying as a image . how to set source for a painter->drawImage(target,image,source) ???

                1 Reply Last reply
                0
                • J Jaswenth S
                  void DialWidget::drawImage(QPainter *painter)
                  {
                       QImage pix("J:/#Curneu/UI/Head Positioning/front.png");
                       QRectF target(m_SIDE_LENGTH / 2, m_SIDE_LENGTH / 2,80,60);
                       QRectF source(m_SIDE_LENGTH / 2, m_SIDE_LENGTH / 2,4.0,4.0);
                       painter->save();
                        painter->drawImage(target,pix,source);
                       painter->restore();
                  }
                  

                  So this is the function that i am using and I didn't get any errors but , I can't able to see the image at the center of the dial . Help me with this

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

                  Hi,

                  @Jaswenth-S said in How top place a Image incide a custom dial without using Qml:

                  QImage pix("J:/#Curneu/UI/Head Positioning/front.png");

                  That path looks wrong.

                  Did you check that the image is successfully loaded ?

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

                  J 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Hi,

                    @Jaswenth-S said in How top place a Image incide a custom dial without using Qml:

                    QImage pix("J:/#Curneu/UI/Head Positioning/front.png");

                    That path looks wrong.

                    Did you check that the image is successfully loaded ?

                    J Offline
                    J Offline
                    Jaswenth S
                    wrote on last edited by
                    #8

                    @SGaist no I didn't check , how to check that the image is loaded.

                    mrjjM 1 Reply Last reply
                    0
                    • J Jaswenth S

                      @SGaist no I didn't check , how to check that the image is loaded.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #9

                      @Jaswenth-S
                      Hi
                      You can check with
                      https://doc.qt.io/qt-5/qpixmap.html#isNull
                      if it was loaded.

                      You are using an overload that also accepts a rect for source.
                      Do you mean to only use some part of the image ?
                      as else you can just draw it without the source and full image is used.
                      https://doc.qt.io/qt-5/qpainter.html#drawImage-4
                      this will also scale the image to the rest.
                      So it the goal to fit the image to some rect or do you just want to draw the image as is ?

                      J 1 Reply Last reply
                      2
                      • mrjjM mrjj

                        @Jaswenth-S
                        Hi
                        You can check with
                        https://doc.qt.io/qt-5/qpixmap.html#isNull
                        if it was loaded.

                        You are using an overload that also accepts a rect for source.
                        Do you mean to only use some part of the image ?
                        as else you can just draw it without the source and full image is used.
                        https://doc.qt.io/qt-5/qpainter.html#drawImage-4
                        this will also scale the image to the rest.
                        So it the goal to fit the image to some rect or do you just want to draw the image as is ?

                        J Offline
                        J Offline
                        Jaswenth S
                        wrote on last edited by
                        #10

                        @mrjj
                        I got the output bro... Thankyou ...

                        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