PDA

View Full Version : QTreewidgetitem signal



mkkguru
22nd January 2010, 07:12
i have a getting problem related to Qtreewidgetitem signals ,when iam using the below code the entire treewidget items getting the connections so i need to get the connectionns to particular item..plz go through the code and mention the changes has to be done..

QTreeWidgetItem *plc = new QTreeWidgetItem(ui->treeWidget);
plc->setText(0,QString("PLC %1").arg(i));

if(plc)
{
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(plcconfig()));
}

QTreeWidgetItem *plcItem = new QTreeWidgetItem(plc);
plcItem->setText(0, tr("CONFIGURATION"));
plc->addChild(plcItem);

QTreeWidgetItem *cpuconfig = new QTreeWidgetItem(plcItem);
cpuconfig->setText(0, tr("CPU CONFIGURATION"));
plcItem->addChild(cpuconfig);

// if(cpuconfig)
// {
// connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showCPU()));
// }

QTreeWidgetItem *varconfig = new QTreeWidgetItem(plcItem);
varconfig->setText(0, tr("VARIABLE CONFIGURATION"));
plcItem->addChild(varconfig);

QTreeWidgetItem *progconfig = new QTreeWidgetItem(varconfig);
progconfig->setText(0, tr("PROGRAM VARIABLE CONFIGURATION"));
varconfig->addChild(progconfig);

if(varconfig)
{
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showpvc()));
}

As iam using above signal when iam cliicking on PROGRAM VARIABLE CONF..... the required window has to opened as below.

void ECLogic::showpvc( )
{
QTabBar *tab_4=new QTabBar(ui->widgetConf);
PCD= new programvariableconfiguration(tab_4);
PCD->setWindowTitle(QString("PVC"));
tabwidget3->insertTab(0,tab_4,QString("PVC"));
tab_4->setCurrentIndex(tabwidget3->indexOf(ui->widgetConf));
tab_4->setTabsClosable(true);
tab_4->setEnabled(true);
PCD->show();
}

but my problem is getting the connections to all the treewidggetitems not for the particular....is there any way to get my condtion ....so please suggests me the way to write the code........

Avijit
22nd January 2010, 07:46
QTreeWidgetItem *plc = new QTreeWidgetItem(ui->treeWidget);
plc->setText(0,"PLC");

QTreeWidgetItem *plcItem = new QTreeWidgetItem(plc);
plcItem->setText(0, tr("CONFIGURATION"));
plc->addChild(plcItem);

QTreeWidgetItem *cpuconfig = new QTreeWidgetItem(plcItem);
cpuconfig->setText(0, tr("CPU CONFIGURATION"));
plcItem->addChild(cpuconfig);



QTreeWidgetItem *varconfig = new QTreeWidgetItem(plcItem);
varconfig->setText(0, tr("VARIABLE CONFIGURATION"));
plcItem->addChild(varconfig);

QTreeWidgetItem *progconfig = new QTreeWidgetItem(varconfig);
progconfig->setText(0, tr("PROGRAM VARIABLE CONFIGURATION"));
varconfig->addChild(progconfig);


connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(chooseConfig(QTreeWidgetItem *,int )));


void ECLogic::chooseConfig(QTreeWidgetItem *item,int i)
{
if(item->text(0)=="PROGRAM VARIABLE CONFIGURATION")
{
showpvc();
}
else if(item->text(0)=="CPU CONFIGURATION")
{
showCPU();
}
else if(item->text(0)=="PLC")
{
plcconfig();
}

}

void ECLogic::showpvc( )
{
QTabBar *tab_4=new QTabBar(ui->widgetConf);
PCD= new programvariableconfiguration(tab_4);
PCD->setWindowTitle(QString("PVC"));
tabwidget3->insertTab(0,tab_4,QString("PVC"));
tab_4->setCurrentIndex(tabwidget3->indexOf(ui->widgetConf));
tab_4->setTabsClosable(true);
tab_4->setEnabled(true);
PCD->show();
}

aamer4yu
22nd January 2010, 07:56
You should make the showpvc() slot to same signature as itemClicked. Then in the slot you can check which item was clicked and perform actions based on it.

showpvc ( QTreeWidgetItem * item, int column )
{
if( item == varconfig )
// do something when varconfig is clicked
else if( item == progconfig )
// do something when progconfigis clicked
}