<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Multiple backgrounds colors one for each line of a Qlabel (pyQt5)]]></title><description><![CDATA[<p dir="auto">hello,<br />
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.<br />
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 block</p>
<pre><code>        numberOfGroupsName=" "
        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+"&lt;br&gt; "
                        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)
</code></pre>
<p dir="auto">(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)</p>
<p dir="auto">![alt text](<img src="https://ddgobkiprc33d.cloudfront.net/514c1a5e-89e7-4f49-8c39-e6fff0e983c6.png" alt="93ee037a-97e7-40a0-adc7-05825e4d3aaa-image.png" class=" img-fluid img-markdown" /> image url)<br />
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'<br />
thanks</p>
]]></description><link>https://forum.qt.io/topic/143034/multiple-backgrounds-colors-one-for-each-line-of-a-qlabel-pyqt5</link><generator>RSS for Node</generator><lastBuildDate>Fri, 19 Jun 2026 21:00:28 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/143034.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 17 Feb 2023 07:35:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Multiple backgrounds colors one for each line of a Qlabel (pyQt5) on Mon, 20 Feb 2023 09:04:48 GMT]]></title><description><![CDATA[<p dir="auto">to reproduce it the easiest possible:</p>
<pre><code>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&lt;br&gt;X&lt;br&gt;X&lt;br&gt;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()
</code></pre>
<p dir="auto">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))</p>
]]></description><link>https://forum.qt.io/post/748423</link><guid isPermaLink="true">https://forum.qt.io/post/748423</guid><dc:creator><![CDATA[otaolafr]]></dc:creator><pubDate>Mon, 20 Feb 2023 09:04:48 GMT</pubDate></item></channel></rss>