Page 1 of 2 12 LastLast
Results 1 to 20 of 70

Thread: How to show progess in a QTreeView item ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to show progess in a QTreeView item ?

    There is no real progressbar. But you can access the value displayed using a line similar to this one:
    Qt Code:
    1. int progress = index.data(Qt::DisplayRole).toInt();
    To copy to clipboard, switch view to plain text mode 
    In your case you might want to substitute index with item approach receiving:
    Qt Code:
    1. int progress = item->data(Qt::DisplayRole).toInt();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show progess in a QTreeView item ?

    Thank you for the response Wysota,

    So if I wanted to update it continuously with progress I would need to access it with?

    Qt Code:
    1. item->setData(1,Qt::DisplayRole,updatingValue);
    To copy to clipboard, switch view to plain text mode 

    Bob

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to show progess in a QTreeView item ?

    Yes, that's correct.

  4. #4
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show progess in a QTreeView item ?

    Using the example from jpn I call

    Qt Code:
    1. tree.topLevelItem(1)->setData(1,Qt::DisplayRole,50);
    To copy to clipboard, switch view to plain text mode 

    and then

    Qt Code:
    1. qDebug() << tree.topLevelItem(1)->data(1,Qt::DisplayRole).toInt();
    To copy to clipboard, switch view to plain text mode 

    to confirm the value has changed but I do not get an update in the GUI displayed progress column. Do I need to also call a repaint or some other event?

    Bob

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to show progess in a QTreeView item ?

    The example generates dummy progress values. Substitute
    Qt Code:
    1. int progress = (index.row() != 0 ? 100 / index.row() : 0);
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. int progress = index.data(Qt::DisplayRole).toInt();
    To copy to clipboard, switch view to plain text mode 
    in ItemDelegate::paint().
    J-P Nurmi

  6. #6
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show progess in a QTreeView item ?

    Thank you Wysota and jpn,

    One last question on this subject, in jpn's example the maximum size is set

    Qt Code:
    1. opt.maximum = 100;
    To copy to clipboard, switch view to plain text mode 

    Is there a way to set a different maximum for each item?

    Bob

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to show progess in a QTreeView item ?

    You could use for example custom roles. Qt::UserRole is the first role that can be used for application-specific purposes:
    Qt Code:
    1. // define custom roles
    2. const int MinimumRole = Qt::UserRole;
    3. const int MaximumRole = MinimumRole + 1;
    4.  
    5. // set data for custom roles
    6. item->setData(column, MinimumRole, minimum);
    7. item->setData(column, MaximumRole, maximum);
    8.  
    9. // get data for custom roles
    10. opt.minimum = index.data(MinimumRole).toInt();
    11. opt.maximum = index.data(MaximumRole).toInt();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to show progess in a QTreeView item ?

    You could even add a ValueRole and then use DisplayRole for something else (like displaying some text).

  9. #9
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to show progess in a QTreeView item ?

    the examples in this 3D are about Qt4, is it? there is a way to do the same thing (a progress bar in a colum of a QListView) for Qt 3.3.5?

  10. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show progess in a QTreeView item ?

    Yes, the thread is about Qt 4.
    In Qt 3 you cannot do it like that. You can instead subclass QListViewItem and paint the progress yourself.
    See Q3ListViewItem::paintCell()

  11. #11
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to show progess in a QTreeView item ?

    Quote Originally Posted by marcel View Post
    Yes, the thread is about Qt 4.
    In Qt 3 you cannot do it like that. You can instead subclass QListViewItem and paint the progress yourself.
    See Q3ListViewItem::paintCell()
    ok thanxs...do you know if there are some examples about this?

  12. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show progess in a QTreeView item ?

    Well, no examples that I know of, but you can play with it.
    Basically you could keep the progress value in your item subclass and just consider it when doing the repainting. It shouldn't be that hard - you have the painter, the width and height of the cell... Just paint a rectangle with the width of progressValue*cellWidth/100 in the cell.

  13. #13
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to show progess in a QTreeView item ?

    Quote Originally Posted by marcel View Post
    Well, no examples that I know of, but you can play with it.
    Basically you could keep the progress value in your item subclass and just consider it when doing the repainting. It shouldn't be that hard - you have the painter, the width and height of the cell... Just paint a rectangle with the width of progressValue*cellWidth/100 in the cell.

    well...I modified the paincell for myListyViewItem to create a progress bar like I want.
    now I want update the progress bar for each row of the list every 1 second.
    Any idea to do this ask???
    I thought to create for each item a qtimer that every second update ther percent of the progress and call the paintcell but I don't know how call well the paintcell function.

  14. #14
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show progess in a QTreeView item ?

    I thought to create for each item a qtimer that every second update ther percent of the progress a call the paintcell but I don't know how call well the paintcell function.
    That's not really good. Why not create a single timer, on whose timeout() you will update all items.
    You can call either one of the Q3ListView::updateContents() functions or Q3ListView::repaintItem() for all items.

  15. #15
    Join Date
    Dec 2007
    Posts
    119
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to show progess in a QTreeView item ?

    Quote Originally Posted by marcel View Post
    That's not really good. Why not create a single timer, on whose timeout() you will update all items.
    You can call either one of the Q3ListView::updateContents() functions or Q3ListView::repaintItem() for all items.
    ok ... I try...and now that I have a myListViewItem how can I iterate the listview to modify each item? The QLIstViewItemIterator is seem to don't work.

  16. #16
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show progess in a QTreeView item ?

    Quote Originally Posted by fruzzo View Post
    ok ... I try...and now that I have a myListViewItem how can I iterate the listview to modify each item? The QLIstViewItemIterator is seem to don't work.
    How come it doesn't work?
    This is the example from Assistant:
    Qt Code:
    1. QList<Q3ListViewItem *> lst;
    2. Q3ListViewItemIterator it(myListView);
    3. while (it.current()) {
    4. if (it.current()->isSelected())
    5. lst.append(it.current());
    6. ++it;
    7. }
    To copy to clipboard, switch view to plain text mode 
    So, it pretty much should work.

  17. #17
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to show progess in a QTreeView item ?

    It appears that style sheets can not be used with QItemDelegate. Is it so ? If it is how can I apply styles to my widgets ?
    Thanks
    C++ & AMD forever

  18. #18
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to show progess in a QTreeView item ?

    Quote Originally Posted by THRESHE View Post
    It appears that style sheets can not be used with QItemDelegate. Is it so ?
    That's right, unfortunately. Luckily Qt 4.4 will introduce QStyledItemDelegate.
    J-P Nurmi

  19. #19
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to show progess in a QTreeView item ?

    But QStyle can be used for styling or not ? And if it can is it much harder to use QStyle instead style sheets ? Thanks
    C++ & AMD forever

  20. #20
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to show progess in a QTreeView item ?

    Quote Originally Posted by THRESHE View Post
    But QStyle can be used for styling or not ? And if it can is it much harder to use QStyle instead style sheets ?
    Sure it can. Well, writing a custom QStyle subclass is same as painting stuff by hand whereas style sheets are way more abstract way to style applications. I suggest you take a sneak peak to src/gui/styles/qxxxstyle.cpp what it looks like to implement a custom style.
    J-P Nurmi

  21. The following user says thank you to jpn for this useful post:

    THRESHE (27th February 2008)

Similar Threads

  1. Replies: 4
    Last Post: 26th September 2011, 12:02
  2. QTreeView and item editing
    By roxton in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 18:56
  3. QTreeView, QSortFilterProxyModel and item expansions
    By benacler in forum Qt Programming
    Replies: 3
    Last Post: 21st May 2008, 20:30
  4. QTreeView: selection behavior upon selected item removal
    By Pieter from Belgium in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2007, 16:00
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 14:24

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.