Code Monkey home page Code Monkey logo

animloop-qt's Introduction

animloop-qt

alt text

This code is a simple example of one way to do a minimal QGraphicsScene animation in Qt. This does not use QML.

In this example, a circle moves downwards and to the right. The blue box depicts the boundary of the QGraphicsScene, and the window dimensions are 100 pixels larger than the QGraphicsView dimensions. A 60ms signal/slot timer is used to fire off each tick of the animation loop. This code has been kept simple in a small number of files to make it beginner-friendly.

For beginning programmers, try playing with the setGeometry values for the scene and the view in mainwindow.cpp to get an idea of how they relate to each other, when scrollbars appear, etc. What happens when you make the scene bigger than the view? What happens when you make the window smaller than the view, and/or the scene? Change the values and see what happens. Also notice that the circle will still be rendered when it leaves scene edge, but it disappears when it leaves the view edge.

Another fun exercise for beginners would be to make the circle "bounce" off the scene boundary, so that it stays within the blue box, or add other moving circles, or otherwise change the animation somehow.

This code is copyright 2017 isc1 and is free for anyone to use under the MIT license. This code was written on Desktop Qt 5.9.0 MinGW 32-bit (Windows), and might not build successfully on later versions of Qt, or on other platforms such as Linux or MacOS, without modification.

THIS CODE IS UNSUPPORTED and no one is available to respond to questions or comments about it.

If you are new to Qt, try the following links. (None of these links are affiliated with this repository or it's author in any way.)

animloop-qt's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

xingkong1989

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.