Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why if no TreeWidgetItem was clicked the signal itemPressed no emitt?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ljc123456gogo
    wrote on last edited by ljc123456gogo
    #1

    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

    Keep Hungery, Keep Foolish!

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      0
      • jsulmJ jsulm

        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.

        L Offline
        L Offline
        ljc123456gogo
        wrote on last edited by
        #3

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

        Keep Hungery, Keep Foolish!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved