Python Forum
[PyQt] coloring the widget table row
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] coloring the widget table row
#1
hi;
I created a graphical application with Qtdesigner and pyqt5. To finalize it completely, I started the creation some retouches concerning the coloring of some particular lines of the widget table.here is a reduced part of the code the application of my project

creation of the base and table :

    
def create_database_ils35R(self):
        
	#creating the path to the current folder :
	os.chdir('D:\\workspace_python\\Application_ddm')
    #directory creation 'data_base'
	os.makedirs("D:\\workspace-python\\Application ddm\\data_base", exist_ok=True)          
	#values recovered and introduced into the table 
	date_reading = str(time.strftime("%d-%m-%Y"))
	time_reading = str(time.strftime('%H:%M:%S'))    
	mon1_reading = self.lineEdit_mon1_reading.text()
	mon2_reading = self.lineEdit_mon2_reading.text()
	confirmation = self.lineEdit_confirmation.text()
	#creation and connexion to the database "ils35R"
	connexion = sqlite3.connect('data_base/ils35R.db') 
	# Get a cursor object
	curseur = connexion.cursor()
	# Check if table loc35R does not exist and create it
	curseur.execute('''CREATE TABLE IF NOT EXISTS loc35R (date text, time text,mon1 text, mon2 text,declaration text ) ''')
	#inserting data into table "loc35R" :
	curseur.execute('''INSERT INTO loc35R VALUES (?,?,?,?,?) ''',(date_reading,time_reading, mon1_reading, mon2_reading, confirmation))         
	# Commit the change
	connexion.commit()                     
	#fermeture du cursor
	curseur.close()
	#fermeture de la connexion à la bdd
	connexion.close()
display the contents of the data table in a widget table :

def display_contents_table_loc35R(self):

	os.chdir('D:\\workspace-python\\Application_ddm')
	conn = sqlite3.connect ('data_base/ils35R.db')
	curseur=conn.cursor()

	c=curseur.execute("SELECT * FROM loc35R")
              
	liste_loc35R=c.fetchall()
	# set row count
	self.tableWidget_loc35R.setRowCount(len(liste_loc35R))
          
	for nb in range(len(liste_loc35R)):
		for nombre in range(5):
			self.tableWidget_loc35R.setItem(nb,nombre, QTableWidgetItem(liste_loc35R[nb][nombre]))
        
		self.tableWidget_loc35R.resizeRowsToContents()
		self.tableWidget_loc35R.resizeColumnsToContents()        
            
	#closing the cursor
	curseur.close()

	#closing the connection to the bdd
	conn.close()
   
state checkbutton confirmation :

def state checkbutton_for_correction_loc35R(self):
     
if self.checkBox_loc35R.isChecked()==True :	     
	self.lineEdit_confirmation.setText("OK")
            
else:	                      
	self.lineEdit_confirmation.setText("NO")
the insertion of the data in the table and recovery of this information and the display is done successfully on a table wiget pyqt5.

[Image: 7lnt.jpg]

The problem I encountered and I do not have to find a solution: I want the row of the table containing the confirmation information to be entirely according to the state of the checkbutton: to have green background for each row of the table widget when checkbutton is checked.: (that is to say each row that whose confirmation column contains the OK string

thanks for help
Reply


Messages In This Thread
coloring the widget table row - by atlass218 - Aug-09-2019, 08:36 PM
RE: coloring the widget table row - by Alfalfa - Aug-10-2019, 12:32 AM
RE: coloring the widget table row - by atlass218 - Aug-10-2019, 05:52 AM
RE: coloring the widget table row - by Alfalfa - Aug-10-2019, 12:22 PM
RE: coloring the widget table row - by atlass218 - Aug-20-2019, 08:10 AM
RE: coloring the widget table row - by Axel_Erfurt - Aug-20-2019, 07:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyQt Selected row in Table Widget rarevesselt 3 23,793 Dec-07-2018, 07:00 PM
Last Post: rarevesselt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020