Results 1 to 7 of 7

Thread: QProgressBar as a QTreeView item

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Apr 2011
    Location
    Palma de Mallorca, Islas Baleares, Spain
    Posts
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows
    Thanks
    5
    Thanked 5 Times in 5 Posts

    Lightbulb Re: QProgressBar as a QTreeView item

    I did a little class to show a QProgressBar:

    ProgressDialog.h:
    Qt Code:
    1. /*
    2.  * ProgressDialog.h
    3.  *
    4.  * Created on: 26/08/2011
    5.  * Author: Sergio Madrazo Giménez
    6.  */
    7.  
    8. #include <QDialog>
    9. #include <QProgressBar>
    10. #include <QHBoxLayout>
    11. #ifndef PROGRESSDIALOG_H_
    12. #define PROGRESSDIALOG_H_
    13.  
    14. class ProgressDialog : public QDialog{
    15.  
    16. Q_OBJECT
    17.  
    18. public:
    19. ProgressDialog(QWidget *parent=0, int t=0);
    20. virtual ~ProgressDialog();
    21.  
    22. private:
    23. int total;
    24. QProgressBar *progressBar;
    25.  
    26. public slots:
    27. void setNuber(int num);
    28. };
    29.  
    30. #endif /* PROGRESSDIALOG_H_ */
    To copy to clipboard, switch view to plain text mode 
    ProgressDialog.cpp
    Qt Code:
    1. /*
    2.  * ProgressDialog.cpp
    3.  *
    4.  * Created on: 26/08/2011
    5.  * Author: Sergio Madrazo Giménez
    6.  */
    7. #include <QtGui>
    8. #include "ProgressDialog.h"
    9.  
    10. ProgressDialog::ProgressDialog(QWidget *parent, int t)
    11. : QDialog(parent)
    12. {
    13. total = t;
    14.  
    15. progressBar = new QProgressBar (parent);
    16. progressBar->setRange(0,100);
    17. progressBar->setValue(50);
    18. progressBar->setVisible(true);
    19. progressBar->setMaximumSize(500,30);
    20. progressBar->setMinimumSize(200,30);
    21. }
    22.  
    23. ProgressDialog::~ProgressDialog() {
    24. delete progressBar;
    25. }
    26.  
    27.  
    28. /********************************
    29.  ************ SLOTS *************
    30.  ********************************/
    31.  
    32. /*
    33.  * This slot changes the value of the progress bar.
    34.  * Input: number of items.
    35.  * It calculates automatically the percentage
    36.  */
    37. void ProgressDialog::setNuber(int num){
    38. progressBar->setValue((num*100)/total);
    39. }
    To copy to clipboard, switch view to plain text mode 

    This class has two paremeters imput:
    1. QWidget *parent: When you call the constructor you can put it the Widget that you want. If you put 0, the it will open a new window.
    2. int t: this is the total. For example, if you have 5 things to do, it will be 5. Every time you finish one thing you call the method setImage with the number you finished.


    Sorry for my poor english!

  2. The following user says thank you to sergio87 for this useful post:


Similar Threads

  1. QTreeView Checkable Item
    By fruzzo in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2011, 10:41
  2. Extract Item from the QTreeView
    By sajis997 in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2011, 08:40
  3. Add Item in QDIRMODEL + QTREEVIEW
    By kamlmish in forum Newbie
    Replies: 0
    Last Post: 7th January 2011, 08:35
  4. Buttons on item in QTreeView?
    By joeld42 in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2010, 01:27
  5. QTreeView and item editing
    By roxton in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 18:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.