Why if no TreeWidgetItem was clicked the signal itemPressed no emitt?



  • Hi!
    I see the document say:

    void QTreeWidget::itemPressed(QTreeWidgetItem * item, int column)

    This signal is emitted when the user presses a mouse button inside the widget.

    The specified item is the item that was clicked, or 0 if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.

    When I connect itemPressed to My slot void EditCurrentItem(QTreeWidgetItem* currentItem, int column):

    connect(m_ui.m_TreeWidget,SIGNAL(itemPressed(QTreeWidgetItem*, int)),this,SLOT(EditCurrentItem(QTreeWidgetItem*, int)));
    

    if the item that was clicked the sinal will be emitted. But when I cancel click item(click on the blank space Inside the TreeWidget), no itemPressed be emit? I don't knowWhy.

    image1

    image2

    the SLOT void EditCurrentItem(QTreeWidgetItem* currentItem, int column) as below:

    void QuesManager::EditCurrentItem(QTreeWidgetItem* currentItem, int column)
    {
    	if(currentItem != 0)
    	{
    		m_ui.m_Title->setText(currentItem->text(2));
    		m_ui.m_Ans->setText(currentItem->text(3));
    	}
    	else
    	{
    		m_ui.m_Title->setText("");
    		m_ui.m_Ans->setText("");
    	}
    }
    

    The small project had been upload to the Attachment.(My Qt version is 5.5 and using VS2010)
    Thanks help me!

    See Attachment:
    https://github.com/ljcduo/TempAns1


  • Moderators

    Hi!
    Well, why should this signal be emitted if you do not click on an item?
    It is only emitted if you click on an item (that's why it is called itemPressed) if you click on something else it is not emitted.
    If you want to know when nothing is selected then use http://doc.qt.io/qt-5/qtreewidget.html#itemSelectionChanged.



  • @jsulm Thanks! I Change itemPressed to itemSelectionChanged, It works!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.