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. problem to set the colour of the 0 column
Forum Updated to NodeBB v4.3 + New Features

problem to set the colour of the 0 column

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 233 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
    FaTr
    wrote on last edited by
    #1

    Hi
    When i colour the column 1 of QTableWidget I have no issue at all. see the picture
    Capture.PNG

    once i change the coloumn in the cycle for number at 0

    self.ui.table_testpoint.item(r, 0).setBackground(QtGui.QColor(204, 255, 255))
    

    I have the error : AttributeError: 'NoneType' object has no attribute 'setBackground'

    below my code. Please dont look the indentations.

    with open(namefile, newline='') as csvfile:
    				
        reader = csv.DictReader(csvfile)
        self.ui.table_testpoint.setRowCount(lines)  #insert the index coloum in the table
    				
        r = 0
    
        for row in reader:
    			
            self.ui.table_testpoint.setItem(r, 1, QTableWidgetItem(row["V1"]))
            self.ui.table_testpoint.setItem(r, 3, QTableWidgetItem(row["V2"]))
            self.ui.table_testpoint.setItem(r, 5, QTableWidgetItem(row["Freq"]))
            self.ui.table_testpoint.setItem(r, 6, QTableWidgetItem(row["load"]))
            self.ui.table_testpoint.setItem(r, 11, QTableWidgetItem(row["StepTime"]))
            try:
    	    self.ui.table_testpoint.item(r, 0).setBackground(QtGui.QColor(204, 255, 255))
            except:
    	    print(f"no color set for row {r}")
             r +=1
    
    jsulmJ 1 Reply Last reply
    0
    • F FaTr

      Hi
      When i colour the column 1 of QTableWidget I have no issue at all. see the picture
      Capture.PNG

      once i change the coloumn in the cycle for number at 0

      self.ui.table_testpoint.item(r, 0).setBackground(QtGui.QColor(204, 255, 255))
      

      I have the error : AttributeError: 'NoneType' object has no attribute 'setBackground'

      below my code. Please dont look the indentations.

      with open(namefile, newline='') as csvfile:
      				
          reader = csv.DictReader(csvfile)
          self.ui.table_testpoint.setRowCount(lines)  #insert the index coloum in the table
      				
          r = 0
      
          for row in reader:
      			
              self.ui.table_testpoint.setItem(r, 1, QTableWidgetItem(row["V1"]))
              self.ui.table_testpoint.setItem(r, 3, QTableWidgetItem(row["V2"]))
              self.ui.table_testpoint.setItem(r, 5, QTableWidgetItem(row["Freq"]))
              self.ui.table_testpoint.setItem(r, 6, QTableWidgetItem(row["load"]))
              self.ui.table_testpoint.setItem(r, 11, QTableWidgetItem(row["StepTime"]))
              try:
      	    self.ui.table_testpoint.item(r, 0).setBackground(QtGui.QColor(204, 255, 255))
              except:
      	    print(f"no color set for row {r}")
               r +=1
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @FaTr You do not set any items in column 0 as far as I can see (so item(r, 0) returns None), that is why you get this error.

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

      1 Reply Last reply
      2

      • Login

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