QTreeWidget clicked signal
Hi,
I'm having problems to get a signal when I click on a QTreeWidget. The problem is that if no item is selected there is no signal emmited.
I need to know if I clicked on an empy region of the Tree because I have actions that I have to enable or diable depending on the item that is clicked. But if I click out of any item I would all the actions disabled.
Thanks,
Re: QTreeWidget clicked signal
Try this:
Just make sure clicking outside any item clears the selection.
Re: QTreeWidget clicked signal
Hi,
I have tryied it. It connects but the signal is only emmited when I click on a item.
Re: QTreeWidget clicked signal
Do it lowlevel then. Reimplement the mouseReleaseEvent of the widget and use itemAt() to check the item under cursor.
Re: QTreeWidget clicked signal
Hi,
So, have I to inherit from QTreeWidget and reimplement the "mouseReleaseEvent" function?
Thanks,
Re: QTreeWidget clicked signal
Hi,
Anyone knows how to make it? Have I to inherit from QTreeWidget and reimplement "mouseReleaseEvent" function or there is another way?
Thanks,
Re: QTreeWidget clicked signal
Hmm.... Could you read my last post again? :)
Re: QTreeWidget clicked signal
Hi,
Ok, Ok, so ther isn't another way.
Thanks,
Re: QTreeWidget clicked signal
i too have a getting same problem related to treewidget item signals ,
Code:
plc
->setText
(0,
QString("PLC %1").
arg(i
));
if(plc)
{
connect(ui
->treeWidget,
SIGNAL(itemClicked
(QTreeWidgetItem *,
int)),
this,
SLOT(plcconfig
()));
}
plcItem->setText(0, tr("CONFIGURATION"));
plc->addChild(plcItem);
cpuconfig->setText(0, tr("CPU CONFIGURATION"));
plcItem->addChild(cpuconfig);
// if(cpuconfig)
// {
// connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showCPU()));
// }
varconfig->setText(0, tr("VARIABLE CONFIGURATION"));
plcItem->addChild(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.
Code:
void ECLogic::showpvc( )
{
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........
Re: QTreeWidget clicked signal
You get the pointer to the item in the signal so you can check its contents in the slot.
Re: QTreeWidget clicked signal
how can i set the pointer to the signal, we can't set values in connect statements.we should use types there.
Try this:
connect(ui.tree, SIGNAL(itemClicked (QTreeWidgetItem*,int)), this, SLOT(showplc()))
Re: QTreeWidget clicked signal
Quote:
Originally Posted by
mkkguru
how can i set the pointer to the signal, we can't set values in connect statements.we should use types there.
I didn't say anything about "pointers to signals" nor did I say about setting a value in a connect statement.
Code:
// ...
if(item) {
// ...
} else {
// ...
}
}
Re: QTreeWidget clicked signal
actually i have to write many signals to QTreewidgetitems so when i clikcing on item other signals also working ,so i need to stop getting other windows...only particular window when we click on Qtreewidgetitem has to opened.......
Re: QTreeWidget clicked signal
I don't understand what you mean.
Re: QTreeWidget clicked signal
i have to get connections to particular item when we clik.......and no other connections has to established to treewidgetitems
Re: QTreeWidget clicked signal
So? What's the problem? Can't you check if the item that you want was clicked and if not then simply do nothing?
Re: QTreeWidget clicked signal
// connections written in constructor
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(maybeShowpvc(QTreeWidgetItem*))) ;
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(maybeShowplc(QTreeWidgetItem*))) ;
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(maybeShowioc(QTreeWidgetItem*))) ;
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem ,int)),this,SLOT(maybeShowldr(QTreeWidgetItem*)));
// slot methods
void X::maybeShowpvc(QTreeWidgetItem *plc)
{
if(item){
plc->show();
......
// code
}
void X::maybeShowplc(QTreeWidgetItem *pvc)
{
//connection code
pvc->show();
.............
}
void X::maybeShowpvc(QTreeWidgetItem *ioc)
{
//connection code
.....
}
void X::maybeShowldr(QTreeWidgetItem *ldr)
{
//connection code
.....
}
when iam using above code all the connections and slots are working at a time...........is there any possibility to get the connections to particular item (plc,pvc,ioc,ldr) ...
Re: QTreeWidget clicked signal
You dont need separate slots, you need only one slot.
Code:
{
if(item == plcItem)
plc->show();
else if(item == pvcItem)
pvc->show();
...
}
where plcItem and pvcItem are the QTreeWidgetItems you have added in your tree.
Re: QTreeWidget clicked signal
I think that mkkguru misunderstood or misused word "connection". Can you explain in other words what do you mean by "getting the connection to particular item"?
Just to make things clear:
connect() method only sets the signal and slot in such way, that if signal is emitted then the connected slot is called (with emitted arguments). So if you connect your QTreeWidget itemClicked(QTreeWidgetItem *, int) signal to 4 slots, then clicking on item will emit one signal ONCE but this will call every slot connected to your signal, so all your 4 slots will be called. But you did not notice that there is QTreeWidgetItem* argumet in that signal, which is there to let you know what item was clicked. So in your case there should be one slot connected to this itemClicked() signal, where depending on information retrieved from given QTreeWidgetItem*, you will know that this clicked item is pvc, plc, ioc, etc...
1 Attachment(s)
Re: QTreeWidget clicked signal
Image shows the treewidget ,when we click on item the particular item window has to opend.
//connection
//slots method
Code:
{
if(item == lnx)
{
ECLogic_Lnx=new eclogic_lnx(main_tab_widget);
ECLogic_Lnx
->setWindowTitle
(QString("ECLOGIC-LNX"));
ECLogic_Lnx->show();
}
else
if(item == plc)
tab_3
=new QTabBar(main_tab_widget
);
PLCconfig=new plcconfiguration(tab_3);
PLCconfig
->setWindowTitle
(QString("PLC"));
main_tab_widget
->insertTab
(0,tab_3,
QString("PLC"));
tab_3->setCurrentIndex(main_tab_widget->indexOf(tab_3));
PLCconfig->show();
}
When iam using above code the connecting to other windows are not getting ,where ECLogic_Lnx , PLCconfig,.. are window names.
where lnx,plc,...are qtreewidgetitem obj names,so is there any method to check the condition
[