Results 1 to 6 of 6

Thread: QProgressBar in QTreeWidget?

  1. #1
    Join Date
    Jul 2008
    Location
    Netherlands
    Posts
    33
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QProgressBar in QTreeWidget?

    I have a QTreeWidget that displays information. It only has top level items, each having 5 fields. Right now, these 5 columns are all text (QString). The last one represents some kind of progress, so I'd like this to be a progress bar (QProgressBar).

    The documentation of QTreeWidget says:
    void QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget )
    Sets the given widget to be displayed in the cell specified by the given item and column.
    Note that the given widget's autoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the tree widget item.
    This function should only be used to display static content in the place of a tree widget item. If you want to display custom dynamic content or implement a custom editor widget, use QTreeView and subclass QItemDelegate instead.
    This function was introduced in Qt 4.1.
    See also itemWidget() and Delegate Classes.
    So, supposedly I can set any widget for any cell. But I'm unsure of what is meant with
    This function should only be used to display static content in the place of a tree widget item.
    A progress bar is not static, so it's implied I cannot use it. Or does "static" refer to the fact that it should remain the same widget one it's set?
    Or should I use QAbstractItemModel with QTreeView instead? (I have tried this approach briefly, but with no success so far. I'd like to use the QTreeWidget, because it's easier to use, rather that putting many hours in the abstract model.)

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProgressBar in QTreeWidget?

    why you can't write your own delegate with progress bar?

  3. #3
    Join Date
    Jul 2008
    Location
    Netherlands
    Posts
    33
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressBar in QTreeWidget?

    How do you mean?
    I'm not very familiar with the MVC idea, and I was hoping to get by the easy way
    I tried to just use QTreeWidget::setItemWidget() and it seems to work just fine. I was just wondering if this is a good approach, or that I'm doing it all wrong...

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProgressBar in QTreeWidget?

    simple delegate example
    Qt Code:
    1. QWidget *MyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. QProgressBar *bar = new QProgressBar(parent);
    4. bar->setMaximum(100);
    5. bar->setValue(50);
    6. return bar;
    7. }
    8.  
    9. void MyItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const
    10. {
    11. editor->setGeometry(option.rect);
    12. }
    To copy to clipboard, switch view to plain text mode 

    in widget:
    Qt Code:
    1. ...
    2. QTableWidget *tw = new QTableWidget(10, 2, this);
    3. tw->setItemDelegate(new MyItemDelegate);
    4. ...
    To copy to clipboard, switch view to plain text mode 

  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: QProgressBar in QTreeWidget?

    J-P Nurmi

  6. #6
    Join Date
    Jul 2008
    Location
    Netherlands
    Posts
    33
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressBar in QTreeWidget?

    Quote Originally Posted by jpn View Post
    Thank you for pointing me there. Your example in that thread is extremely useful!

    I'm not sure whether I forgot to search or used the wrong terms, but I definitely need to sleep more

Similar Threads

  1. QTreeWidget Drag and Drop
    By tommydent in forum Qt Programming
    Replies: 10
    Last Post: 25th August 2008, 15:25
  2. QTreeWidget nextSibling()
    By user_mail07 in forum Newbie
    Replies: 1
    Last Post: 21st August 2008, 19:44
  3. QTreeWidget click
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2007, 16:47
  4. how to add icons to QTreeWidget?
    By wei243 in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2007, 08:34
  5. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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.