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. Artificial Horizon like in Mission Planer
QtWS25 Last Chance

Artificial Horizon like in Mission Planer

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.1k 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
    BrMisha
    wrote on last edited by
    #1

    Hi!
    I need to make Artificial Horizon like in Mission Planer http://ardupilot.org/planner/docs/mission-planner-ground-control-station.html .
    I have found some examples (Qwt and FlightInstruments) but there are oval widgets and I need rectangle.
    May be somebody knows where I can get an example?
    Thanks))

    Pl45m4P Pablo J. RoginaP 2 Replies Last reply
    0
    • B BrMisha

      Hi!
      I need to make Artificial Horizon like in Mission Planer http://ardupilot.org/planner/docs/mission-planner-ground-control-station.html .
      I have found some examples (Qwt and FlightInstruments) but there are oval widgets and I need rectangle.
      May be somebody knows where I can get an example?
      Thanks))

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @brmisha

      Hi,
      build your own :)

      The Misson Planner Horizon Widget is nothing else than a rotating rectangle inside a bounding box (if you ignore the fancy stuff and some scales)

      Have a look here: https://forum.qt.io/topic/105507/setrotation-does-not-react-so-settransformationoriginpoint/2

      https://doc.qt.io/qt-5/qgraphicsitem.html


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      B 1 Reply Last reply
      2
      • B BrMisha

        Hi!
        I need to make Artificial Horizon like in Mission Planer http://ardupilot.org/planner/docs/mission-planner-ground-control-station.html .
        I have found some examples (Qwt and FlightInstruments) but there are oval widgets and I need rectangle.
        May be somebody knows where I can get an example?
        Thanks))

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @brmisha said in Artificial Horizon like in Mission Planer:

        there are oval widgets and I need rectangle.

        Just put such widgets on top of a rectangle, and you're done with such requirement...

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          This type of widget design should be a formal Qt training exercise because it exposes the student to some fundamental concepts of custom paint events and using the QPainter, while creating something that many programmers will eventually want to see anyways.

          1 Reply Last reply
          1
          • Pl45m4P Pl45m4

            @brmisha

            Hi,
            build your own :)

            The Misson Planner Horizon Widget is nothing else than a rotating rectangle inside a bounding box (if you ignore the fancy stuff and some scales)

            Have a look here: https://forum.qt.io/topic/105507/setrotation-does-not-react-so-settransformationoriginpoint/2

            https://doc.qt.io/qt-5/qgraphicsitem.html

            B Offline
            B Offline
            BrMisha
            wrote on last edited by
            #5

            @pl45m4 I need pitch too)))
            I have a good experiences with Qt, but with console apps, whithout witgets.
            Ok, I will try to build my own)))

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BrMisha
              wrote on last edited by
              #6

              In paintEvent

              const int	width = size().width();
              	const int	height = size().height();
              	const int	halfwidth = width/2;
              	const int	halfheight = height/2;
              	const qreal	every5deg = -height / 60;
              	const qreal	pitchoffset = -pitch * every5deg;
              
              	qreal pitch = -13.7;
              	qreal roll = -10.1;
              
              	QPainter painter(this);
              	painter.save();
              
              	painter.translate(width/2, height/2);
              	painter.rotate(-roll);
              
              	qreal offset = 0.5 + pitchoffset / height / 2;
              	if (offset < 0) offset = 0;
              	else if (offset > 1) offset = 1;
              
              	QLinearGradient linearGrad(0, -height, 0, height);
              	linearGrad.setColorAt(0, Qt::cyan);
              	linearGrad.setColorAt(offset > 0 ? offset-0.001 : offset, Qt::cyan);
              	linearGrad.setColorAt(offset < 1 ? offset+0.001 : offset, QRgb(0x9bb824));
              	linearGrad.setColorAt(1, QRgb(0x414f07));
              	QRect	rect(-width, -height, halfwidth * 4, halfheight * 4);
              	painter.fillRect(rect, QBrush(linearGrad));
              
              	// just point at center
              	painter.setBrush(Qt::red);
              	painter.drawEllipse(0, 0, 20, 20);
              
              	painter.restore();
              

              It works)))

              Pablo J. RoginaP 1 Reply Last reply
              0
              • B BrMisha

                In paintEvent

                const int	width = size().width();
                	const int	height = size().height();
                	const int	halfwidth = width/2;
                	const int	halfheight = height/2;
                	const qreal	every5deg = -height / 60;
                	const qreal	pitchoffset = -pitch * every5deg;
                
                	qreal pitch = -13.7;
                	qreal roll = -10.1;
                
                	QPainter painter(this);
                	painter.save();
                
                	painter.translate(width/2, height/2);
                	painter.rotate(-roll);
                
                	qreal offset = 0.5 + pitchoffset / height / 2;
                	if (offset < 0) offset = 0;
                	else if (offset > 1) offset = 1;
                
                	QLinearGradient linearGrad(0, -height, 0, height);
                	linearGrad.setColorAt(0, Qt::cyan);
                	linearGrad.setColorAt(offset > 0 ? offset-0.001 : offset, Qt::cyan);
                	linearGrad.setColorAt(offset < 1 ? offset+0.001 : offset, QRgb(0x9bb824));
                	linearGrad.setColorAt(1, QRgb(0x414f07));
                	QRect	rect(-width, -height, halfwidth * 4, halfheight * 4);
                	painter.fillRect(rect, QBrush(linearGrad));
                
                	// just point at center
                	painter.setBrush(Qt::red);
                	painter.drawEllipse(0, 0, 20, 20);
                
                	painter.restore();
                

                It works)))

                Pablo J. RoginaP Offline
                Pablo J. RoginaP Offline
                Pablo J. Rogina
                wrote on last edited by
                #7

                @brmisha said in Artificial Horizon like in Mission Planer:

                It works)))

                great! Is your issue solved? please don't forget to mark your post as such. Thanks

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                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