Progress BarThis example shows how to use a progressbar. Header file: /**************************************************************************** ** $Id: //depot/qt/main/examples/progressbar/progressbar.h#1 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #ifndef PROGRESSBAR_H #define PROGRESSBAR_H #include <qbuttongroup.h> #include <qtimer.h> class QRadioButton; class QPushButton; class QProgressBar; class ProgressBar : public QButtonGroup { Q_OBJECT public: ProgressBar( QWidget *parent = 0, const char *name = 0 ); protected: QRadioButton *slow, *normal, *fast; QPushButton *start, *pause, *reset; QProgressBar *progress; QTimer timer; protected slots: void slotStart(); void slotReset(); void slotTimeout(); }; #endif Implementation: /**************************************************************************** ** $Id: //depot/qt/main/examples/progressbar/progressbar.cpp#1 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "progressbar.h" #include <qradiobutton.h> #include <qpushbutton.h> #include <qprogressbar.h> #include <qlayout.h> /* * Constructor * * Creates child widgets of the ProgressBar widget */ ProgressBar::ProgressBar( QWidget *parent, const char *name ) : QButtonGroup( 0, Horizontal, "Progress Bar", parent, name ), timer() { setMargin( 10 ); QGridLayout* toplayout = new QGridLayout( layout(), 2, 2, 5); setRadioButtonExclusive( TRUE ); // insert three radiobuttons which the user can use // to set the speed of the progress and two pushbuttons // to start/pause/continue and reset the progress slow = new QRadioButton( "&Slow", this ); normal = new QRadioButton( "&Normal", this ); fast = new QRadioButton( "&Fast", this ); QVBoxLayout* vb1 = new QVBoxLayout; toplayout->addLayout( vb1, 0, 0 ); vb1->addWidget( slow ); vb1->addWidget( normal ); vb1->addWidget( fast ); // two push buttons, one for start, for for reset. start = new QPushButton( "&Start", this ); reset = new QPushButton( "&Reset", this ); QVBoxLayout* vb2 = new QVBoxLayout; toplayout->addLayout( vb2, 0, 1 ); vb2->addWidget( start ); vb2->addWidget( reset ); // Create the progressbar progress = new QProgressBar( 100, this ); toplayout->addMultiCellWidget( progress, 1, 1, 0, 1 ); // connect the clicked() SIGNALs of the pushbuttons to SLOTs connect( start, SIGNAL( clicked() ), this, SLOT( slotStart() ) ); connect( reset, SIGNAL( clicked() ), this, SLOT( slotReset() ) ); // connect the timeout() SIGNAL of the progress-timer to a SLOT connect( &timer, SIGNAL( timeout() ), this, SLOT( slotTimeout() ) ); // Let's start with normal speed... normal->setChecked( TRUE ); // some contraints start->setFixedWidth( 80 ); setMinimumWidth( 300 ); } /* * SLOT slotStart * * This SLOT is called if the user clicks start/pause/continue * button */ void Main: /**************************************************************************** ** $Id: //depot/qt/main/examples/progressbar/main.cpp#1 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "progressbar.h" #include < |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 2.3 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com