python - Set background color of layout -
as layout object has no attribute ".setstylesheet()", how can 1 set background color given layout?
as visual explanation, can set both label , button background color, not entire layout, includes spacer.
programatically, i'm organizing information in horizontal layouts , displaying them in frame. alternate background colors each loop.
for param_name in parameters: hlayouts.append(qtgui.qhboxlayout()) labels.append(qtgui.qlabel("%s"%param_name)) sliders.append(qtgui.qspaceritem(10,10,hpolicy=qtgui.qsizepolicy.expanding)) spins.append(qtgui.qdoublespinbox()) spins[index].setvalue(float(values.get(param_name))) labels[index].setstylesheet("background-color:black;") spins[index].setstylesheet("background-color:black;") hlayouts[index].addwidget(labels[index]) hlayouts[index].additem(sliders[index]) hlayouts[index].addwidget(spins[index]) index += 1 vlayout = qtgui.qvboxlayout() in range(len(hlayouts)): vlayout.addlayout(hlayouts[i])
you add set layout on empty qwidget , set stylesheet on widget.
for index, param_name in enumerate(parameters): container = qtgui.qwidget(self) layout = qtgui.qhboxlayout(container ) hlayouts.append(container) labels.append(qtgui.qlabel("%s"%param_name)) sliders.append(qtgui.qspaceritem(10,10,hpolicy=qtgui.qsizepolicy.expanding)) spins.append(qtgui.qdoublespinbox()) spins[index].setvalue(float(values.get(param_name))) container.setstylesheet("background-color:black;") layout.addwidget(labels[index]) layout.additem(sliders[index]) layout.addwidget(spins[index]) vlayout = qtgui.qvboxlayout(self) widget in hlayouts: vlayout.addwidget(widget)
Comments
Post a Comment