[Qt-interest] Problems with QTreeWidget HeaderView

Sarvesh Saran Sarvesh.Saran at synopsys.com
Wed Jan 13 07:04:50 CET 2010


Hi,

I am having problems trying to set the headers for my tree widget. For whatever reason, an extra column or space appears at right end of the widget, something like this:

[cid:image001.png at 01CA9444.6A9F4430]

I can't seem to figure out how to get rid of the last column space. I would like the total space to be split between the 4 columns and the column width should be such that header text  be clearly
Visible (the width could be more but never less than the header text Wight). The code looks something like this:

    QStringList headers;
     headers << tr("header1") << tr("header2")<<tr("header3")<<tr("header4");

    QTreeWidgetItem *headeritem = new QTreeWidgetItem(headers);
    headeritem->setTextAlignment(0,Qt::AlignHCenter);
    headeritem->setTextAlignment(1,Qt::AlignHCenter);
    headeritem->setTextAlignment(2,Qt::AlignHCenter);
    headeritem->setTextAlignment(3,Qt::AlignHCenter);
    ui.TreeWidget->setHeaderItem(headeritem);
    ui.TreeWidget->setHeaderLabels(headers);
    ui.TreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui.TreeWidget->setRootIsDecorated(true);
    ui.TreeWidget->setAlternatingRowColors(true);


  QHeaderView *header = ui.TreeWidget->header();
    header->setResizeMode(0, QHeaderView::ResizeToContents);
    header->setResizeMode(3, QHeaderView::ResizeToContents);
    header->setResizeMode(1, QHeaderView::ResizeToContents);
    header->setResizeMode(2, QHeaderView::ResizeToContents);

any ideas?

Thanks,
Sarvesh

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100113/71313ccd/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 1353 bytes
Desc: image001.png
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100113/71313ccd/attachment.png 


More information about the Qt-interest-old mailing list