Results 1 to 20 of 42

Thread: QTreeWidget clicked signal

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget clicked signal

    Try this:
    Qt Code:
    1. connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(yourSlotGoesHere()));
    To copy to clipboard, switch view to plain text mode 
    Just make sure clicking outside any item clears the selection.

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget clicked signal

    Hi,

    I have tryied it. It connects but the signal is only emmited when I click on a item.
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget clicked signal

    Do it lowlevel then. Reimplement the mouseReleaseEvent of the widget and use itemAt() to check the item under cursor.

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget clicked signal

    Hi,

    So, have I to inherit from QTreeWidget and reimplement the "mouseReleaseEvent" function?

    Thanks,
    Òscar Llarch i Galán

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    Òscar Llarch i Galán

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget clicked signal

    Hmm.... Could you read my last post again?

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget clicked signal

    Hi,

    Ok, Ok, so ther isn't another way.

    Thanks,
    Òscar Llarch i Galán

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

    Default Re: QTreeWidget clicked signal

    i too have a getting same problem related to treewidget item signals ,

    Qt Code:
    1. QTreeWidgetItem *plc = new QTreeWidgetItem(ui->treeWidget);
    2. plc->setText(0,QString("PLC %1").arg(i));
    3.  
    4. if(plc)
    5. {
    6. connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(plcconfig()));
    7. }
    8.  
    9. QTreeWidgetItem *plcItem = new QTreeWidgetItem(plc);
    10. plcItem->setText(0, tr("CONFIGURATION"));
    11. plc->addChild(plcItem);
    12.  
    13. QTreeWidgetItem *cpuconfig = new QTreeWidgetItem(plcItem);
    14. cpuconfig->setText(0, tr("CPU CONFIGURATION"));
    15. plcItem->addChild(cpuconfig);
    16.  
    17. // if(cpuconfig)
    18. // {
    19. // connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showCPU()));
    20. // }
    21.  
    22. QTreeWidgetItem *varconfig = new QTreeWidgetItem(plcItem);
    23. varconfig->setText(0, tr("VARIABLE CONFIGURATION"));
    24. plcItem->addChild(varconfig);
    25.  
    26. QTreeWidgetItem *progconfig = new QTreeWidgetItem(varconfig);
    27. progconfig->setText(0, tr("PROGRAM VARIABLE CONFIGURATION"));
    28. varconfig->addChild(progconfig);
    29.  
    30. if(varconfig)
    31. {
    32. connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showpvc()));
    33. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. void ECLogic::showpvc( )
    2. {
    3. QTabBar *tab_4=new QTabBar(ui->widgetConf);
    4. PCD= new programvariableconfiguration(tab_4);
    5. PCD->setWindowTitle(QString("PVC"));
    6. tabwidget3->insertTab(0,tab_4,QString("PVC"));
    7. tab_4->setCurrentIndex(tabwidget3->indexOf(ui->widgetConf));
    8. tab_4->setTabsClosable(true);
    9. tab_4->setEnabled(true);
    10. PCD->show();
    11. }
    To copy to clipboard, switch view to plain text mode 

    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........
    Last edited by wysota; 22nd January 2010 at 10:04. Reason: Missing [code] tags

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget clicked signal

    You get the pointer to the item in the signal so you can check its contents in the slot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default 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()))

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.