[Qt-interest] qtreewidget
phil prentice
philp.cheer at talktalk.net
Wed Jun 30 18:27:13 CEST 2010
Hi
I am producing a dialog which uses a QTreeWidget. I have a number of
questions regarding it. I have included the main function that is working
with the QTreeWidget.
The main problem that I have is that my table has two sets of headings.
A top level heading that sits on a group of lower level headings...
First and second rows are headings...data follows.
| NETWORK | CHAN WIRING | CHAN ROUTING |
| Active | Name | Type | Number | Module | Highway |
| True | FRED1 | DIG | 100 | DS | DF |
| True | FRED1 | DIG | 100 | DS | DF |
.....
Using QTreeWidget is there any clever way of handling these headings? I could
not see anything that would help me.
What I did in the end was fix each of the column widths in pixels and created
the one QLABEL = "NETWORK CHAN WIRING CHAN ROUTING"
and suitably spaced it out to appear above the QTreeWidget columns. I stopped
the dialogs width from being modified and fixed it at an appropriate width.
It seems to work, but I was wondering if there is a better way?
I know that I am depending on the font being the same, but in my case this
should not be a problem.
Is it bad programming practise that I have fixed the column widths or is that
perfectly acceptable?
Any help appreciated
Phil
Code:-
void NetIdDialog::createAndLayoutNetworkRoutingTab()
{
// Create "NETWORK INFO & ROUTING" widgets.
m_networkLabel = new QLabel(
" NETWORK "
"CHANNEL WIRING "
"CHANNEL ROUTING");
m_netRoutingTreeWidget = new QTreeWidget();
m_netRouting = new QWidget();
// Add headings
m_netRoutingTreeWidget->setColumnCount(7);
QTreeWidgetItem *header = m_netRoutingTreeWidget->headerItem();
header->setText(0, "Active");
header->setText(1, "Name");
header->setText(2, "Type");
header->setText(3, "Number");
header->setText(4, "Force/Sense");
header->setText(5, "Module");
header->setText(6, "Routing Highway");
setMaximumWidth(725);
setMinimumWidth(725);
m_netRoutingTreeWidget->setColumnWidth(0, 50);
m_netRoutingTreeWidget->setColumnWidth(1, 190);
m_netRoutingTreeWidget->setColumnWidth(2, 50);
m_netRoutingTreeWidget->setColumnWidth(3, 70);
m_netRoutingTreeWidget->setColumnWidth(4, 100);
m_netRoutingTreeWidget->setColumnWidth(5, 70);
m_netRoutingTreeWidget->setColumnWidth(6, 200);
// Do Layout.
QHBoxLayout *firstRowLayout = new QHBoxLayout;
firstRowLayout->addWidget(m_networkLabel);
firstRowLayout->addStretch();
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(firstRowLayout);
mainLayout->addWidget(m_netRoutingTreeWidget);
m_netRouting->setLayout(mainLayout);
}
More information about the Qt-interest-old
mailing list