Results 1 to 3 of 3

Thread: QTreewidgetitem signal

  1. #1
    Join Date
    Oct 2009
    Posts
    35
    Thanks
    12
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11

    Default QTreewidgetitem signal

    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........

  2. #2
    Join Date
    Jan 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreewidgetitem signal

    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();
    }

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreewidgetitem signal

    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.
    Qt Code:
    1. showpvc ( QTreeWidgetItem * item, int column )
    2. {
    3. if( item == varconfig )
    4. // do something when varconfig is clicked
    5. else if( item == progconfig )
    6. // do something when progconfigis clicked
    7. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 4
    Last Post: 30th September 2009, 11:59
  2. signal mapping on pushbutton signal clicked
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 07:54
  3. QTreeWidgetItem signal or event
    By db in forum Newbie
    Replies: 1
    Last Post: 20th October 2007, 14:18
  4. QTreeWidgetItem ?
    By allensr in forum Qt Programming
    Replies: 5
    Last Post: 3rd January 2007, 17:51
  5. From extends QTreeWidgetItem emit signal?
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 19th May 2006, 14:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.