Results 1 to 5 of 5

Thread: how to show vertical lines between colums

  1. #1
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question how to show vertical lines between colums

    hi all
    i am using Qt4.1 on Mac OS

    the idea is to showing the vertical lines between colums of QTreeWidget
    as i have 4 colums in treewidget.
    how it can be done???

    and how data coming in all colums should be aligned squarely or in proper manner???


    thanks in advance

  2. #2
    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 vertical lines between colums

    I don't think there's any built-in way for doing that. What you can do is to reimplement paintEvent() and paint them yourself. The header provides information about column (section) positions and sizes.
    J-P Nurmi

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

    thomasjoy (22nd August 2007)

  4. #3
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Default Re: how to show vertical lines between colums

    can you please explai how it can be done in simple example with no. of items are there in TreeWidget

  5. #4
    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 vertical lines between colums

    Alright, here's an example:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class TreeWidget : public QTreeWidget
    4. {
    5. public:
    6. TreeWidget(QWidget* parent = 0) : QTreeWidget(parent)
    7. {
    8. setColumnCount(5);
    9. }
    10.  
    11. protected:
    12. void paintEvent(QPaintEvent* event)
    13. {
    14. QTreeWidget::paintEvent(event);
    15. QPainter painter(viewport());
    16. for (int i = 0; i < header()->count(); ++i)
    17. {
    18. // draw only visible sections starting from second column
    19. if (header()->isSectionHidden(i) || header()->visualIndex(i) <= 0)
    20. continue;
    21.  
    22. // position mapped to viewport
    23. int pos = header()->sectionViewportPosition(i) - 1;
    24. if (pos > 0)
    25. painter.drawLine(QPoint(pos, 0), QPoint(pos, height()));
    26. }
    27. }
    28.  
    29. void scrollContentsBy(int dx, int dy)
    30. {
    31. QTreeWidget::scrollContentsBy(dx, dy);
    32. // make sure lines get updated even if the view is empty
    33. viewport()->update();
    34. }
    35. };
    36.  
    37. int main(int argc, char *argv[])
    38. {
    39. QApplication app(argc, argv);
    40. TreeWidget tree;
    41. tree.show();
    42. return app.exec();
    43. }
    To copy to clipboard, switch view to plain text mode 
    You could use for example QStyle::SH_Table_GridLineColor as pen color.
    J-P Nurmi

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

    thomasjoy (22nd August 2007)

  7. #5
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Default Re: how to show vertical lines between colums

    thanks for such a nice example

    but i dont have to use qpen or Qpaint properties...

    can we disable the streching of treewidget's header
    i.e header should be of fixed width

Similar Threads

  1. Subclass QListView to show two colums in one
    By Mookie in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2007, 03:12

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.