Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-168

QtCore.Alignment objects are not correctly interpreted when returned from item.data()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.0
    • 1.1.2
    • PySide
    • Windows 7, Python 2.7.4

    Description

      Inside QtCore.QAbstractItemModel.data() we might have code like this

              if role == QtCore.Qt.TextAlignmentRole:
                  if case_a:
                      return QtCore.Qt.AlignRight
                  elif case_b:
                      return QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter
                  else:
                      return QtCore.Qt.AlignVCenter
      

      Case a works (kind of) in that we get right alignment but vertical alignment changes from the AlignVCenter default to AlignTop.

      Case b does not work: the alignment value is ignored.

      Case c works.

      What seems to be going on is that the caller of data() expects an int return not an Alignment object. If we replace by

              if role == QtCore.Qt.TextAlignmentRole:
                  if case_a:
                      return int(QtCore.Qt.AlignRight)
                  elif case_b:
                      return int(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
                  else:
                      return int(QtCore.Qt.AlignVCenter)
      

      it works.

      Simple example enclosed.

      Attachments

        1. alligntest.py
          4 kB
        2. pyside168.py
          4 kB
        3. pyside-168-alligntest.py
          4 kB

        Issue Links

          For Gerrit Dashboard: PYSIDE-168
          # Subject Branch Project Status CR V

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              bstrulo Ben Strulo
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes