Multiple backgrounds colors one for each line of a Qlabel (pyQt5)
-
hello,
I am doing an interface that presents different groups of objects (outside of the interface) where each of them has a different color. the idea is to create an easy way to see which line corresponds to which object. for this reason, in the pyQt interface, I am creating an small qLabel that i leave 'empty' of text, and i change the background of it.
this worked nicely as intended see groups 0, 2, 4, 6. my 'issue' or what I am having trouble with, is that now some objects are parents with their own children (so some groups are dependent of others), and I can not get around to make the 'square' of color, of all the different colors for the parent and children groups. the part of the code that modify this, is cited below, I am not 100% if this is feasible at all, just for info, it remaining color for the blocknumberOfGroupsName=" " colorOfTheGroup="background:rgb("+str(Colors[i][0])+","+str(Colors[i][1])+","+str(Colors[i][2])+")" if i in listOfAxisParents: for j in relationsOfAxis: if i==j[0]: for k in j[1]: numberOfGroupsName=numberOfGroupsName+"<br> " colorOfTheGroup=colorOfTheGroup+",rgb("+str(Colors[k][0])+","+str(Colors[k][1])+","+str(Colors[k][2])+")" colorOfTheGroup=colorOfTheGroup+";" w[i] = QLabel(numberOfGroupsName) w[i].setStyleSheet(colorOfTheGroup) w[i].setFixedWidth(20) layout_1.addWidget(w[i],i+1,0,1,1)(the one that should be divided into 3 for this example, it is colored as the color of the last group in position k, so group 5)

I am not sure if the issue commes from the way I created the variable colorOfTheGroup, meaning I might be misswriting this, or if it is even possible to give, 'different backgrounds to different lines of a qlabel'
thanks -
hello,
I am doing an interface that presents different groups of objects (outside of the interface) where each of them has a different color. the idea is to create an easy way to see which line corresponds to which object. for this reason, in the pyQt interface, I am creating an small qLabel that i leave 'empty' of text, and i change the background of it.
this worked nicely as intended see groups 0, 2, 4, 6. my 'issue' or what I am having trouble with, is that now some objects are parents with their own children (so some groups are dependent of others), and I can not get around to make the 'square' of color, of all the different colors for the parent and children groups. the part of the code that modify this, is cited below, I am not 100% if this is feasible at all, just for info, it remaining color for the blocknumberOfGroupsName=" " colorOfTheGroup="background:rgb("+str(Colors[i][0])+","+str(Colors[i][1])+","+str(Colors[i][2])+")" if i in listOfAxisParents: for j in relationsOfAxis: if i==j[0]: for k in j[1]: numberOfGroupsName=numberOfGroupsName+"<br> " colorOfTheGroup=colorOfTheGroup+",rgb("+str(Colors[k][0])+","+str(Colors[k][1])+","+str(Colors[k][2])+")" colorOfTheGroup=colorOfTheGroup+";" w[i] = QLabel(numberOfGroupsName) w[i].setStyleSheet(colorOfTheGroup) w[i].setFixedWidth(20) layout_1.addWidget(w[i],i+1,0,1,1)(the one that should be divided into 3 for this example, it is colored as the color of the last group in position k, so group 5)

I am not sure if the issue commes from the way I created the variable colorOfTheGroup, meaning I might be misswriting this, or if it is even possible to give, 'different backgrounds to different lines of a qlabel'
thanks -
hello,
I am doing an interface that presents different groups of objects (outside of the interface) where each of them has a different color. the idea is to create an easy way to see which line corresponds to which object. for this reason, in the pyQt interface, I am creating an small qLabel that i leave 'empty' of text, and i change the background of it.
this worked nicely as intended see groups 0, 2, 4, 6. my 'issue' or what I am having trouble with, is that now some objects are parents with their own children (so some groups are dependent of others), and I can not get around to make the 'square' of color, of all the different colors for the parent and children groups. the part of the code that modify this, is cited below, I am not 100% if this is feasible at all, just for info, it remaining color for the blocknumberOfGroupsName=" " colorOfTheGroup="background:rgb("+str(Colors[i][0])+","+str(Colors[i][1])+","+str(Colors[i][2])+")" if i in listOfAxisParents: for j in relationsOfAxis: if i==j[0]: for k in j[1]: numberOfGroupsName=numberOfGroupsName+"<br> " colorOfTheGroup=colorOfTheGroup+",rgb("+str(Colors[k][0])+","+str(Colors[k][1])+","+str(Colors[k][2])+")" colorOfTheGroup=colorOfTheGroup+";" w[i] = QLabel(numberOfGroupsName) w[i].setStyleSheet(colorOfTheGroup) w[i].setFixedWidth(20) layout_1.addWidget(w[i],i+1,0,1,1)(the one that should be divided into 3 for this example, it is colored as the color of the last group in position k, so group 5)

I am not sure if the issue commes from the way I created the variable colorOfTheGroup, meaning I might be misswriting this, or if it is even possible to give, 'different backgrounds to different lines of a qlabel'
thanksto reproduce it the easiest possible:
from PyQt5.QtWidgets import QWidget, QMessageBox from PyQt5 import QtCore, QtGui import PyQt5.QtCore as QtCore from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt dialog = QDialog() dialog.setWindowTitle("Input size") layout_0 = QGridLayout(dialog) numberOfGroupsName="X<br>X<br>X<br>X" colorOfTheGroup="background:rgb(0,255,0),rgb(213,1,242),rgb(255,127,0),rgb(9,138,204);" w= QLabel(numberOfGroupsName) layout_0.addWidget(w,0,0,1,1) w.setStyleSheet(colorOfTheGroup) w.setFixedWidth(20) dialog.show()here we can see that the different lines of w, (that is X,X,X,X) show all the same last color (ie., rgb(9,138,204))