Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. What signal is emitted while `CurrentItem` is changed in a View?
Forum Updated to NodeBB v4.3 + New Features

What signal is emitted while `CurrentItem` is changed in a View?

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 2 Posters 333 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.
  • N Offline
    N Offline
    NYBL
    wrote on last edited by NYBL
    #1

    I have a QListView that every time i click on an item it sets a QLable text the same as the Item like this

    def set_label_text(self, index)
        text_for_label = some_model.data(index, qtc.Qt.DisplayRole)
        label.setText( text_for_label )
    

    It is connected to clicked signal of the QListView like this:

            sites_box.clicked.connect(self.set_label_text)
    
    
    

    I want to Test it in my tests suite so i thought to invoke item selection like this

         rows = sites_model.rowCount()
            iv = {}
            for row in range(rows):
                model_text = some_model.data(sites_model.index(row, 0), qtc.Qt.DisplayRole)
                some_view.selectionModel().setCurrentIndex(
                    sites_model.index(row,0), qtc.QItemSelectionModel.ClearAndSelect
                )
                label_text = self.mainWin.ui.stackedWidget.findChild(qtw.QLabel).text()
                self.assertEqual(model_text,label_text)
    

    But the apparently this dosent invokes the clicked signal so the label isn't changing..
    Is there ant other signal i can connect to?.

    TLSb.gif

    jsulmJ 1 Reply Last reply
    0
    • N Offline
      N Offline
      NYBL
      wrote on last edited by
      #3

      [SOLVED]
      some_view.selectionModel().currentChanged.connect(func)

      1 Reply Last reply
      1
      • N NYBL

        I have a QListView that every time i click on an item it sets a QLable text the same as the Item like this

        def set_label_text(self, index)
            text_for_label = some_model.data(index, qtc.Qt.DisplayRole)
            label.setText( text_for_label )
        

        It is connected to clicked signal of the QListView like this:

                sites_box.clicked.connect(self.set_label_text)
        
        
        

        I want to Test it in my tests suite so i thought to invoke item selection like this

             rows = sites_model.rowCount()
                iv = {}
                for row in range(rows):
                    model_text = some_model.data(sites_model.index(row, 0), qtc.Qt.DisplayRole)
                    some_view.selectionModel().setCurrentIndex(
                        sites_model.index(row,0), qtc.QItemSelectionModel.ClearAndSelect
                    )
                    label_text = self.mainWin.ui.stackedWidget.findChild(qtw.QLabel).text()
                    self.assertEqual(model_text,label_text)
        

        But the apparently this dosent invokes the clicked signal so the label isn't changing..
        Is there ant other signal i can connect to?.

        TLSb.gif

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @NYBL https://doc.qt.io/qt-5/qabstractitemview.html#activated

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

        N 1 Reply Last reply
        0
        • N Offline
          N Offline
          NYBL
          wrote on last edited by
          #3

          [SOLVED]
          some_view.selectionModel().currentChanged.connect(func)

          1 Reply Last reply
          1
          • jsulmJ jsulm

            @NYBL https://doc.qt.io/qt-5/qabstractitemview.html#activated

            N Offline
            N Offline
            NYBL
            wrote on last edited by
            #4

            @jsulm
            This workes only for doubleClick

            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