Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Artificial Horizon like in Mission Planer

    General and Desktop
    4
    7
    580
    Loading More Posts
    • 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
      BrMisha last edited by

      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))

      Pl45m4 Pablo J. Rogina 2 Replies Last reply Reply Quote 0
      • Pl45m4
        Pl45m4 @BrMisha last edited by 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


        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 Reply Quote 2
        • Pablo J. Rogina
          Pablo J. Rogina @BrMisha last edited by

          @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 Reply Quote 1
          • Kent-Dorfman
            Kent-Dorfman last edited by

            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 Reply Quote 1
            • B
              BrMisha @Pl45m4 last edited by

              @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 Reply Quote 0
              • B
                BrMisha last edited by

                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. Rogina 1 Reply Last reply Reply Quote 0
                • Pablo J. Rogina
                  Pablo J. Rogina @BrMisha last edited by

                  @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 Reply Quote 0
                  • First post
                    Last post