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. QTableWidgetItem - type
Forum Updated to NodeBB v4.3 + New Features

QTableWidgetItem - type

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 2 Posters 860 Views 1 Watching
  • 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.
  • MasterQM Offline
    MasterQM Offline
    MasterQ
    wrote on last edited by MasterQ
    #1

    Hi,

    I am fiiling a QTableWidget with data while the QTableWidgetItems are generated by two different ways.

    self.ui.tableEntries.setItem(0, ABVF.BESCHREIBUNG, QTableWidgetItem("any text"))
    

    and

    witem = QTableWidgetItem(locale.format_string("%.2f", 3.14159, True, True))
    witem.setTextAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight)
    self.ui.tableEntries.setItem(0, ABVF.AUSGABE, witem)
    

    When I then want to access the items by another method

    self.ui.tableEntries.item(0, ABVF.BESCHREIBUNG).data(Qt.ItemDataRole.DisplayRole)
    self.ui.tableEntries.item(0, ABVF.AUSGABE).data(Qt.ItemDataRole.DisplayRole)
    

    I get errors.

    For column ABVF.BESCHREIBUNG everything works fine, for column ABVF.AUSGABE I get

    AttributeError: 'NoneType' object has no attribute 'data'. This depends not on the column index, since I have more than one column set by each way. If the QTableWidgetItem is created directly in the setItem-method is different as if created separately.

    Why is QTableWidgetItem for column ABVF.AUSGABE a NoneType?

    All data are shown correctly in the table! No column is missing, all cells are filled!

    The constructor of QTableWidgetItem has a default parameter type:int. What is meant by that parameter? Is this one of QTabWidgetItem.ItemType? Trying

    witem = QTableWidgetItem(locale.format_string("%.2f", 3.15149, True, True), QTableWidgetItem.ItemType.Type)
    

    changes nothing.

    --EDIT:--

    it is coming from locale.string_format. I have still no clue why.

    JonBJ 2 Replies Last reply
    0
    • MasterQM Offline
      MasterQM Offline
      MasterQ
      wrote on last edited by MasterQ
      #4

      OK, I found my mistake.

      It is not because of locale.string_format. Two of the columns are to separated positive and negative values. One is holding all positives and the other all negativs.

      If a positive value is found I created a QTableWidgetItem for the 'positive' column but forgott the create one for the 'negative' column and vice versa.

      Stupid!

      1 Reply Last reply
      1
      • MasterQM MasterQ

        Hi,

        I am fiiling a QTableWidget with data while the QTableWidgetItems are generated by two different ways.

        self.ui.tableEntries.setItem(0, ABVF.BESCHREIBUNG, QTableWidgetItem("any text"))
        

        and

        witem = QTableWidgetItem(locale.format_string("%.2f", 3.14159, True, True))
        witem.setTextAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight)
        self.ui.tableEntries.setItem(0, ABVF.AUSGABE, witem)
        

        When I then want to access the items by another method

        self.ui.tableEntries.item(0, ABVF.BESCHREIBUNG).data(Qt.ItemDataRole.DisplayRole)
        self.ui.tableEntries.item(0, ABVF.AUSGABE).data(Qt.ItemDataRole.DisplayRole)
        

        I get errors.

        For column ABVF.BESCHREIBUNG everything works fine, for column ABVF.AUSGABE I get

        AttributeError: 'NoneType' object has no attribute 'data'. This depends not on the column index, since I have more than one column set by each way. If the QTableWidgetItem is created directly in the setItem-method is different as if created separately.

        Why is QTableWidgetItem for column ABVF.AUSGABE a NoneType?

        All data are shown correctly in the table! No column is missing, all cells are filled!

        The constructor of QTableWidgetItem has a default parameter type:int. What is meant by that parameter? Is this one of QTabWidgetItem.ItemType? Trying

        witem = QTableWidgetItem(locale.format_string("%.2f", 3.15149, True, True), QTableWidgetItem.ItemType.Type)
        

        changes nothing.

        --EDIT:--

        it is coming from locale.string_format. I have still no clue why.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @MasterQ
        You will get the NoneType if there is indeed no QTableWidgetItem at the specified row, column. Either of the two methods you show should work fine. Consequently please set up a standalone project and test both in (0, 0) and (0, 1) respectively. If that goes wrong please post your exact, minimal code.

        1 Reply Last reply
        0
        • MasterQM MasterQ

          Hi,

          I am fiiling a QTableWidget with data while the QTableWidgetItems are generated by two different ways.

          self.ui.tableEntries.setItem(0, ABVF.BESCHREIBUNG, QTableWidgetItem("any text"))
          

          and

          witem = QTableWidgetItem(locale.format_string("%.2f", 3.14159, True, True))
          witem.setTextAlignment(Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignRight)
          self.ui.tableEntries.setItem(0, ABVF.AUSGABE, witem)
          

          When I then want to access the items by another method

          self.ui.tableEntries.item(0, ABVF.BESCHREIBUNG).data(Qt.ItemDataRole.DisplayRole)
          self.ui.tableEntries.item(0, ABVF.AUSGABE).data(Qt.ItemDataRole.DisplayRole)
          

          I get errors.

          For column ABVF.BESCHREIBUNG everything works fine, for column ABVF.AUSGABE I get

          AttributeError: 'NoneType' object has no attribute 'data'. This depends not on the column index, since I have more than one column set by each way. If the QTableWidgetItem is created directly in the setItem-method is different as if created separately.

          Why is QTableWidgetItem for column ABVF.AUSGABE a NoneType?

          All data are shown correctly in the table! No column is missing, all cells are filled!

          The constructor of QTableWidgetItem has a default parameter type:int. What is meant by that parameter? Is this one of QTabWidgetItem.ItemType? Trying

          witem = QTableWidgetItem(locale.format_string("%.2f", 3.15149, True, True), QTableWidgetItem.ItemType.Type)
          

          changes nothing.

          --EDIT:--

          it is coming from locale.string_format. I have still no clue why.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #3

          @MasterQ said in QTableWidgetItem - type:

          it is coming from locale.string_format. I have still no clue why.

          Start, as ever, by simplifying. Remove the , True, True. Try with a format simpler than %.2f. Maybe set locale.setlocale(locale.LC_ALL, '') before the call.

          1 Reply Last reply
          0
          • MasterQM Offline
            MasterQM Offline
            MasterQ
            wrote on last edited by MasterQ
            #4

            OK, I found my mistake.

            It is not because of locale.string_format. Two of the columns are to separated positive and negative values. One is holding all positives and the other all negativs.

            If a positive value is found I created a QTableWidgetItem for the 'positive' column but forgott the create one for the 'negative' column and vice versa.

            Stupid!

            1 Reply Last reply
            1
            • MasterQM MasterQ has marked this topic as solved on

            • Login

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