Important: Please read the Qt Code of Conduct -

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.



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

    void QuesManager::EditCurrentItem(QTreeWidgetItem* currentItem, int column)
    	if(currentItem != 0)

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

    See Attachment:

  • Lifetime Qt Champion

    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

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

Log in to reply