Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PySide newbie question
QtWS25 Last Chance

PySide newbie question

Scheduled Pinned Locked Moved Language Bindings
7 Posts 2 Posters 5.2k 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.
  • F Offline
    F Offline
    farcat
    wrote on last edited by
    #1

    In QAbstractItemModel documentation is says that you have to emit a dataChanged signal after changes via SetData. How do i do that in python?

    Cheers, Lars

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raaghuu
      wrote on last edited by
      #2

      In PySide, all signals reside in a seperate class... Ex -
      @

      This creates a blank window which closes upon mouse-click.

      import sys
      from PySide import QtGui, QtCore

      class Communicate(QtCore.QObject) :
      mySignal = QtCore.Signal() #signal made

      other signals here

      class AClass(QtGui.QWidget) :
      def init(self) :
      super(AClass, self).init()
      self.initUI()

      def initUI(self) :
          self.c = Communicate() #create instance of the signals' class
          self.c.mySignal.connect(self.close) #connect the 'mySignal' signal to QWidget's 'close' method
      

      Setting up the window

          self.setGeometry(300,300,290,150)
          self.setWindowTitle('Emit Signal')
          self.show()
      
      def mousePressEvent(self,event) :
          self.c.mySignal.emit() # reimplement 'mousePressEvent' to emit 'mySignal'
      

      Boilerplate required to run the application

      def main() :
      app = QtGui.QApplication(sys.argv)
      ex = AClass()
      sys.exit(app.exec_())

      if name == 'main' :
      main()

      @

      1 Reply Last reply
      0
      • F Offline
        F Offline
        farcat
        wrote on last edited by
        #3

        Thanks for the quick reply,

        i saw similar examples, but where does this dataChanged(index, index) predefined method (function?) fit in?

        Cheers, Lars

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raaghuu
          wrote on last edited by
          #4

          @
          class MyItemModel(QtCore.QAbstractItemModel) :

          other code here

          def setData(self, index, value[, role = Qt.EditRole]) :
          
          #   code for setting your data
          
              self.dataChanged.emit(topLeft, bottomRight) //... emit the data changed signal
          

          @
          basically the signal is used as a notification when the data changes

          [EDIT] - syntax for signal emitting corrected

          1 Reply Last reply
          0
          • F Offline
            F Offline
            farcat
            wrote on last edited by
            #5

            I must be missing something; i tried you example as follows:

            @
            def setData(self, index, value, role):
            if index.isValid() and index.column() == 0 and role == QtCore.Qt.EditRole:
            index.internalPointer().name = value
            self.dataChanged[index, index].emit() #only the one cell changes
            @

            But i am still getting an error:

            Traceback (most recent call last):
            File "D:\Documents\Code\Eclipse\workspace\FlowWare_1\design\Models.py", line 84, in setData
            self.dataChanged[index, index].emit()
            IndexError: Signature dataChanged() not found for signal: dataChanged

            What am i missing?

            Cheers, Lars

            1 Reply Last reply
            0
            • R Offline
              R Offline
              raaghuu
              wrote on last edited by
              #6

              Hey, my bad there...
              @self.dataChanged[index, index].emit()@
              is wrong... this syntax is for connecting it with a slot( dataChanged[index, index].connect(...) )

              change it to
              @self.dataChanged.emit(index, index)@
              and see if it works

              P.S. i might still be a little wrong as i am not quite experienced in PySide and Python yet... still learning...

              1 Reply Last reply
              0
              • F Offline
                F Offline
                farcat
                wrote on last edited by
                #7

                Yes, that was it, thanks a lot.

                I am still confused, and start on the tutorial again.

                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