[Qt-interest] qtreewidget
Jason H
scorp1us at yahoo.com
Wed Jun 30 19:23:09 CEST 2010
Ah, yes. bad ideas all the way around, but only for one reason:
The user decides the font and size used.
You have to calculate the number of spaces in your hack to match. The biggest differnce is fixed vs non-fixed-width fonts.
You should be able to get te widget pos() of the "active" "type" and "module" widgets and use QFontMetrics to propery space out "Network" "Chan Wiring" and "Chan Routing" in a string. Though As a hack, I's probablt se a table, and align one left in a cell, one center in a cell and one right in a cell and be done with it.
----- Original Message ----
From: phil prentice <philp.cheer at talktalk.net>
To: qt-interest at trolltech.com
Sent: Wed, June 30, 2010 12:27:13 PM
Subject: [Qt-interest] qtreewidget
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);
}
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list