Results 1 to 10 of 10

Thread: few questions related to QTreeWidget

  1. #1
    Join Date
    Feb 2006
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default few questions related to QTreeWidget

    Dear All

    I have been posting to qtforum for few information on QTreeWidget but didn't find suitable solution. Please help me on the following -

    1) How to set row height for QTreeWidget as in QTreeView

    2) How to show(or paint) grid for QTreeWidget as in QTreeView

    3)How to override default alternating row color for QTreeWidget

    and

    4) I need to show status in the right corner of the Toolbar. So, please suggest how to place multiple vertically stacked Qlable in that place.

    Thanks.
    Last edited by prakash; 24th February 2006 at 11:24.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: few questions related to QTreeWidget

    Quote Originally Posted by prakash
    1) How to set row height for QTreeWidget as in QTreeView
    2) How to show(or paint) grid for QTreeWidget as in QTreeView
    QTreeWidget is a QTreeView, so you should be able to do it the same way.

    Quote Originally Posted by prakash
    3)How to override default alternating row color for QTreeWidget
    Get the QPalette object using palette() method, change QPalette::AlternateBase colour and then set the modified palette using setPalette().

    Quote Originally Posted by prakash
    4) I need to show status in the right corner of the Toolbar. So, please suggest how to place multiple vertically stacked Qlable in that place.
    Tool bar? Or did you mean status bar?

  3. #3
    Join Date
    Feb 2006
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: few questions related to QTreeWidget

    Yes in the Toolbar. I have 5 buttons in the toolbar. My program analyses a large file in multiple threads. I need to show how many threads are active and in which stage they are in, using QLabels in the toolbar.

    Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: few questions related to QTreeWidget

    You could try to add those labels using QToolBar::addWidget(). If you add an empty expanding QLabel first, they should be shifted to the right, but I'm not sure if it will work.

  5. #5
    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: few questions related to QTreeWidget

    If you want to align them vertically, you'll have to put them in a layout first and add the layout to the toolbar.

  6. The following user says thank you to wysota for this useful post:

    prakash (27th February 2006)

  7. #6
    Join Date
    Feb 2006
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: few questions related to QTreeWidget

    There is no function to show grid for a QTreeQidget or is't parent QTreeWiew, but QTableView does have these methods. I was confused previously so Please suggest how to drowGrid and set row height in QTreeWiget.

    Thanks.

  8. #7
    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: few questions related to QTreeWidget

    Provide a custom delegate or reimplement QTreeView::drawRow.

  9. #8
    Join Date
    Feb 2006
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: few questions related to QTreeWidget

    Could you please provide me some sample code ?

    Thanks.

  10. #9
    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: few questions related to QTreeWidget

    How does a grid fit to a tree??

  11. #10
    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: few questions related to QTreeWidget

    Quote Originally Posted by jpn
    How does a grid fit to a tree??
    ...unless there are only top level items and root decoration is set to false, which means you have a multi-column list

    Quote Originally Posted by prakash
    Could you please provide me some sample code ?
    If you use the custom delegate approach proposed by wysota:
    override QItemDelegate:aint()
    Qt Code:
    1. void MyItemDelegate::paint(QPainter* p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const
    2. {
    3. QItemDelegate::paint(p, opt, idx);
    4. if (idx.isValid())
    5. {
    6. p->setPen(Qt::DotLine);
    7. p->drawRect(opt.rect);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    And the another approach, override QTreeView::drawRow()
    Qt Code:
    1. void MyTreeWidget::drawRow(QPainter* p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const
    2. {
    3. QTreeWidget::drawRow(p, opt, idx);
    4. for (int col = 0; col < columnCount(); ++col)
    5. {
    6. QModelIndex s = idx.sibling(idx.row(), col);
    7. if (s.isValid())
    8. {
    9. QRect rect = visualRect(s);
    10. p->setPen(Qt::DotLine);
    11. p->drawRect(rect);
    12. }
    13.  
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 10th March 2006 at 07:36.

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

    razvan.petru (10th November 2009)

Similar Threads

  1. Some questions related to Qt tutorials
    By jamadagni in forum Newbie
    Replies: 2
    Last Post: 17th March 2007, 10:51
  2. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32
  3. QTreeWidget questions
    By fellobo in forum Qt Programming
    Replies: 4
    Last Post: 2nd May 2006, 18:39
  4. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.