Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 70

Thread: How to show progess in a QTreeView item ?

  1. #21
    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

  2. #22
    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

  3. #23
    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

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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).

  5. #25
    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 help it has been invaluable.

    Bob

  6. #26
    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?

  7. #27
    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()

  8. #28
    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?

  9. #29
    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.

  10. #30
    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.

  11. #31
    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.

  12. #32
    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.

  13. #33
    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.

  14. #34
    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

  15. #35
    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

  16. #36
    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

  17. #37
    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

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

    THRESHE (27th February 2008)

  19. #38
    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 ?

    Quote Originally Posted by jpn View Post
    I suggest you take a sneak peak to src/gui/styles/qxxxstyle.cpp what it looks like to implement a custom style.
    It's not so easy Could you point me to some easier example ?
    C++ & AMD forever

  20. #39
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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 ?

    Quote Originally Posted by THRESHE View Post
    It's not so easy
    That's the point of him redirecting you there There is an easier example bundled with Qt, but it only does minor changes.

  21. #40
    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 ?

    Quote Originally Posted by wysota View Post
    That's the point of him redirecting you there There is an easier example bundled with Qt, but it only does minor changes.
    If that's easy then I should think about giving up styling my app
    C++ & AMD forever

Similar Threads

  1. Replies: 4
    Last Post: 26th September 2011, 13:02
  2. QTreeView and item editing
    By roxton in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 19:56
  3. QTreeView, QSortFilterProxyModel and item expansions
    By benacler in forum Qt Programming
    Replies: 3
    Last Post: 21st May 2008, 21:30
  4. QTreeView: selection behavior upon selected item removal
    By Pieter from Belgium in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2007, 17:00
  5. paint QTreeView item !!
    By mcenatie in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2006, 15: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.