PDA

View Full Version : problem with tree view



boss_bhat
2nd June 2006, 12:49
Hi all,
415
I am new to Qt programming. Can some body explain how to do it? It looks like tree with buttons as Items. Do I have to use QTreeWidget ?

Thanks in Advance,
Prasanna Bhat

patrik08
2nd June 2006, 12:58
here is a sample QTreeWidget from a static sqlite3 my own sqlplug-in ... adapter...




/* Compose the tree to pick the item from adressess */
void Shop_Main::Compose_Addo()
{
/* addo_tree->clear(); QTreeView QMouseEvent #include <QTreeView><QTreeWidget> */
AddoLoad.clear();
bool attrib;
QString daten;
current_addo_item->setText("");
addo_tree->setMouseTracking(true);
addo_tree->clear();
QStringList countrys = Query_List_Unique(QString( "SELECT DISTINCT land_code FROM %1 order by land_code" ).arg( TABLE_ADDO ));
QStringListIterator i(countrys);
while (i.hasNext()) {
QString coustr = i.next().toLocal8Bit().constData();
QTreeWidgetItem *cou = new QTreeWidgetItem(addo_tree);
cou->setText(0,coustr);
cou->setToolTip (0,tr("Open to Browse."));
addo_tree->expandItem(cou);
QStringList paese = Query_List_Unique(QString( "SELECT DISTINCT ort FROM %1 WHERE land_code='%2' order by ort" ).arg( TABLE_ADDO , coustr));
QStringListIterator o(paese);
while (o.hasNext()) {
QString pas = o.next().toLocal8Bit().constData();
QTreeWidgetItem *paeort = new QTreeWidgetItem(cou);
paeort->setText(0,pas);
paeort->setToolTip (0,tr("Open to Browse."));
paeort->setIcon(0, QIcon(QString::fromUtf8(":/img/img/folder.png")));
resultMap relist = Query_Qmap_Report(QString( "SELECT firma, name, id FROM %1 WHERE ort='%2' and land_code='%3' order by name" ).arg( TABLE_ADDO , pas , coustr));
resultMap::Iterator it;
for ( it = relist.begin(); it != relist.end(); ++it ) {
QStringList roxe = it.value();
int dbid;
QString na = roxe.at(0).toLocal8Bit().constData();
QString nb = roxe.at(1).toLocal8Bit().constData();
QString inte = roxe.at(2).toLocal8Bit().constData();
if (is_numeric(inte)) {
bool ok;
dbid = inte.toInt(&ok);
} else {
dbid = 0;
}
int clientid = CLIENT_BASE + dbid;
attrib = CheckAttributes(dbid);
if (attrib) {
daten =QString("[%3] %1 %2 -si" ).arg(na , nb , QString::number(clientid) );
} else {
daten =QString("[%3] %1 %2 -no" ).arg(na , nb , QString::number(clientid) );
}

QTreeWidgetItem *sigle = new QTreeWidgetItem(paeort);
AddoLoad.append(daten);
sigle->setText(0,daten);
sigle->setIcon(0,QIcon(QString::fromUtf8(":/img/img/ooo-calc.png")));
connect(addo_tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(Safari()));
QApplication::processEvents();
}
}
}

}

/* this is a slot to get value ... */


/* Discovery actived item to grab on db */
void Shop_Main::Safari()
{
int xcol = addo_tree->currentColumn();
QString findertree = addo_tree->currentItem()->text(xcol);
int total = AddoLoad.size();
if (total > 0) {
QStringListIterator i(AddoLoad);
while (i.hasNext()) {
QString itemtext = i.next().toLocal8Bit().constData();
if (itemtext == findertree) {
current_addo_item->setText(itemtext);
}
}
}
}

jacek
2nd June 2006, 13:12
I am new to Qt programming. Can some body explain how to do it? It looks like tree with buttons as Items. Do I have to use QTreeWidget ?
QTreeWidget won't look like this, you could write your own widget that will hold a number of QPushButtons and draw lines between them. It should be fairly easy to do.

wysota
4th June 2006, 21:03
Or use QCanvas (Q3Canvas or a port of QCanvas to Qt4 available from Trolltech ftp server) or even code it yourself. It should be quite easy too, especially if you don't need the rectangles to be actually buttons.

jacek
4th June 2006, 22:03
QStringListIterator i(AddoLoad);
while (i.hasNext()) {
QString itemtext = i.next().toLocal8Bit().constData();
if (itemtext == findertree) {
current_addo_item->setText(itemtext);
}
}
Why do you covert a QString to QByteArray, just to convert it back to QString?

Why don't you just write:
while( i.hasNext() ) {
QString itemtext( i.next() );
if( itemtext == findertree ) {
current_addo_item->setText( itemtext );
}
}