Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Spin Progress bar in Qt

Tags:

qt

qml

Create Spin Progress bar in Qt, I want to show progress bar like the one which appears while loading. Please Find Image enter image description here

My code goes like this

    QProgressBar *pgbar = new QProgressBar();
    pgbar->resize(500,25);
    pgbar->setOrientation(Qt::Horizontal);
    pgbar->setRange(0,99);
    pgbar->setValue(10);
    pgbar->show();
    installOnDevice(destinationSavePath);
    pgbar->hide();

here installOnDevice(destinationSavePath); takes time to process. Currently I am showing Processbar, I dont want to show processbar. Can't I replace with some progress which shows loading image (Rotating) or something similar to that

like image 328
Sharanabasu Angadi Avatar asked Jan 16 '23 00:01

Sharanabasu Angadi


2 Answers

Have a look at the Twitter Mobile example application. In the file demos/declarative/twitter/qml/twitter/TwitterCore/Loading.qml there is an implementation in QML of the exact thing you want to achieve:

import QtQuick 1.0

Image {
    id: loading
    source: "images/loading.png"
    NumberAnimation on rotation {
         from: 0
         to: 360
         running: loading.visible == true
         loops: Animation.Infinite
         duration: 900
     }
}

Update 1 (reflecting the newly posted code):

Employing QML just for a spinning load indicator in your otherwise Qt Widgets based application seems overkill to me. I would use a QMovie in conjunction with a QLabel to display an animated GIF image containing the spinner:

QMovie* spinnerMovie = new QMovie(":/spinner.gif");
QLabel *spinnerLabel = new QLabel(this);
spinnerLabel->setMovie(spinnerMovie);
spinnerMovie->start();

You should also have a look at the documentation for the Qt Resource System to learn how to bundle images with your application and how to load them.

like image 193
sebasgo Avatar answered Jan 24 '23 22:01

sebasgo


In order to change the cursor wou have to use the setCursor function or the setOverrideCursor in order to apply it to the application. You can construct any cursor you want using a QPixmap as constructor argument.

In order to achieve an animation effect you will need a QTimer. At every timer event you have to change the cursor's pixmap in order give the feel of animation.

like image 20
pnezis Avatar answered Jan 24 '23 22:01

pnezis