PDA

View Full Version : From extends QTreeWidgetItem emit signal?



patrik08
19th May 2006, 13:10
How i can emit a signal from this extendet class? on qt4
The q4 doc give a method to set a Qt::Unchecked but not a method to grab or emit
signal from Unchecked or checked.... one way road?


this compile ok but not work.. why?

/* Last item of tree !*/
class QTreeOne : public QObject, public QTreeWidgetItem
{
Q_OBJECT
public:
QTreeOne(QTreeWidgetItem* parent);
int db_id;
void Set_id( int num );
protected:
public:
public slots:
void Put_works();
signals:
void open_db_form(int db_id);
};

QTreeOne::QTreeOne(QTreeWidgetItem* parent) :
QTreeWidgetItem( parent )
{
this->setBackgroundColor(0,QColor(237,237, 237, 237));
this->setFlags(Qt::ItemIsUserCheckable);
this->setCheckState(0,Qt::Unchecked );
connect(this, SIGNAL(itemPressed(QTreeOne*,int)),this, SLOT(Put_works()));
}

void QTreeOne::Set_id( int num )
{
db_id = num;
}

void QTreeOne::Put_works()
{
if (db_id > 0) {
emit open_db_form(db_id);
}
}

jacek
19th May 2006, 13:30
connect(this, SIGNAL(itemPressed(QTreeOne*,int)),this, SLOT(Put_works()));
"this" doesn't emit itemPressed(QTreeOne*,int) signal. You probably wanted to use the QTreeWidget::itemPressed( QTreeWidgetItem*, int ) signal.

patrik08
19th May 2006, 13:44
I wand an existing signal or create a mouse event

from...
this->setCheckState(0,Qt::Unchecked); or public QObject,


how i find the next steep from setCheckState => QTreeWidgetItem?


not work....
connect(this, SIGNAL(itemPressed(QTreeOne*,int)),this, SLOT(Put_works()));
connect(this, SIGNAL(itemPressed(QTreeOne*)),this, SLOT(Put_works()));

jpn
19th May 2006, 14:25
Create the connection in the treewidget, where you create the tree widget items:


// TreeOne* item = new TreeOne(...);
connect(this, SIGNAL(itemPressed(QTreeWidget*,int)), item, SLOT(Put_works()));

patrik08
19th May 2006, 14:54
Super work....
Pleas send my an e-mail & and your Pay-pal account on form:
http://ciz.ch/pdf/Ticket_Form.pdf

I spend 1/2 day to grab signal from QTreeWidgetItem tanks...


void Shop_Main::Compose_Addo()
{
/* addo_tree->clear(); QTreeView QMouseEvent #include <QTreeView><QTreeWidget> */

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' order by name" ).arg( TABLE_ADDO , pas));
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;
}
QString daten =QString("[%1 %2]" ).arg(na , nb );
QTreeOne *sigle = new QTreeOne(paeort);
sigle->Set_id(dbid,daten);
connect(addo_tree, SIGNAL(itemActivated(QTreeWidgetItem*,int)), sigle, SLOT(Put_works()));
QApplication::processEvents();
}
}
}
}

svn co http://ciz.ch/svnciz/forms_shop/ test
cd test && qmake && make