Page 4 of 4 FirstFirst ... 234
Results 61 to 70 of 70

Thread: How to show progess in a QTreeView item ?

  1. #61
    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 are effectively doubling your structures.

    http://blog.wysota.eu.org/index.php/...ta-redundancy/

    The progress is part of your data structure thus the datastructure should be informing the environment through a model (or modifying a set of items, if you insist on using the convenience approach) about every change that happens to it so that the view can update itself properly. How come do you expect the delegate to update the progress if it doesn't know anything changed?

  2. #62
    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
    The progress is part of your data structure thus the datastructure should be informing the environment through a model (or modifying a set of items, if you insist on using the convenience approach) about every change that happens to it so that the view can update itself properly
    How can I do that ?

    Quote Originally Posted by wysota View Post
    How come do you expect the delegate to update the progress if it doesn't know anything changed?
    I wanted to explicitly upadte it something like ItemDelegate->update() and that I could call it from anywhere in my app
    C++ & AMD forever

  3. #63
    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 ?

    Imagine the viewport of the view as a sheet of paper you can draw on. Furthermore imagine you have a set of stamps that you can modify (i.e. change numbers to set a date). The stamp is your delegate - the view can set its attributes and use it to stamp all items in needs on the sheet of paper. The stamp doesn't do anything by itself, it can't be "updated" because a single stamp during a single pass can be used to draw an arbitrary number of different items (the stamp has no state). The view (you) in turn knows how to prepare the stamp because it knows the idea of how the final image should look like - your imagination of the image is the "model". You need to change your imagination to detect that you need to draw something differently on the paper, right? And that's exactly what you need to do - update the model to reflect all new changes.

    You are using the so called convenience widgets which have an internal model and allow manipulation of particular cells through a set of item pointers. So to change the model, you need to change properties of those items - QTreeWidgetItem::setText or QTreeWidgetItem::setData might be good places to start doing some reading.

  4. #64
    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 ?

    wysota I really appreciate that you are trying to help me but it would be much better if you backup your words with code

    For instance if I do like this
    Qt Code:
    1. class QProgressDelegate : public QItemDelegate
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. QProgressDelegate(QObject *parent=0);
    7. ~QProgressDelegate();
    8.  
    9. void paint (QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
    10. void NewProgress(int p)
    11. {
    12. progress = p;
    13. }
    14.  
    15. private:
    16. int progress;
    17. };
    To copy to clipboard, switch view to plain text mode 
    Will calling NewProgress() repaint my progress bar ?
    C++ & AMD forever

  5. #65
    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 ?

    No, it won't.

    Qt Code:
    1. class Dele : public QItemDelegate {
    2. public:
    3. void paint(QPainter *p, const .... &opt, const QModelIndex &ind const {
    4. int val = ind.data(Qt::DisplayRole).toInt();
    5. QRect rect = opt.rect;
    6. rect.setWidth(rect.width()*val/100);
    7. p->drawRect(rect);
    8. }
    9. };
    10.  
    11. QTreeWidget Item *item = ....
    12.  
    13. item->setText(1, 40);
    14. // view will be updated here
    15. item->setText(1, 60);
    16. // view will be updated here
    To copy to clipboard, switch view to plain text mode 

    You have at least two almost complete solution on the very first page of this thread. Didn't you see them?

  6. The following 2 users say thank you to wysota for this useful post:

    Talei (20th January 2010), THRESHE (3rd March 2008)

  7. #66
    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 ?

    Thanks that is what I was asking you
    C++ & AMD forever

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

    And one more question I'd like to ask. I don't know if this is the right topic so don't blame me too much

    The problem is when I click on a row in my table widget it becomes highlighted but when I use delegates it is not. I've tried to do like this
    Qt Code:
    1. if (table->currentRow() == index.row())
    2. {
    3. painter->setBrush(QBrush(QColor("#444444")));
    4. painter->drawRect(opt.rect);
    5. }
    To copy to clipboard, switch view to plain text mode 
    but it didn't work the way I thought. Also I've tried to use setBackground with QPainter and that didn't work either
    C++ & AMD forever

  9. #68
    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 QStyleOptionViewItem parameter contains all required information.
    Qt Code:
    1. if (opt.state & QStyle::State_Selected)
    2. ...
    3.  
    4. if (opt.state & QStyle::State_HasFocus)
    5. ...
    To copy to clipboard, switch view to plain text mode 
    etc.
    J-P Nurmi

  10. #69
    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
    The QStyleOptionViewItem parameter contains all required information.
    Qt Code:
    1. if (opt.state & QStyle::State_Selected)
    2. ...
    3.  
    4. if (opt.state & QStyle::State_HasFocus)
    5. ...
    To copy to clipboard, switch view to plain text mode 
    etc.
    And what after ???
    I've tried like
    Qt Code:
    1. if (opt.state & QStyle::State_Selected)
    2. {
    3. painter->setBrush(QBrush(QColor("#444444")));
    4. painter->drawRect(opt.rect);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Result -
    Attached Images Attached Images
    • File Type: jpg 1.jpg (6.3 KB, 36 views)
    C++ & AMD forever

  11. #70
    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 ?

    Sorry it was something with my brushes now it works fine
    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.