35 from python_qt_binding.QtCore
import Qt
36 from python_qt_binding.QtWidgets
import QWidgetItem, QSpacerItem
46 Alternate the background color of the widgets that are ordered 47 linearly, by the given list of colors. 49 Originally intended for the elements of QHBoxLayout & QVBoxLayout. 51 @type list_widgets: QtGui.QWidget[] 52 @type colors_alter: QtCore.Qt.GlobalColor[] 53 @param colors_alter: 1st element is used as initial/default color. 59 colors_num = len(colors_alter)
61 for w
in list_widgets:
62 w.setAutoFillBackground(
True)
65 divisor = (i_widget + colors_num) % colors_num
68 rospy.logdebug(
'LayoutUtil divisor={} i_widget={} colors_num={}'.format(divisor,
72 p.setColor(w.backgroundRole(), colors_alter[divisor])
78 Clear all items in the given layout. Currently, only the instances of 79 QWidgetItem get cleared (ie. QSpaceItem is ignored). 81 Originally taken from http://stackoverflow.com/a/9375273/577001 85 for i
in reversed(range(layout.count())):
86 item = layout.itemAt(i)
88 if isinstance(item, QWidgetItem):
93 elif isinstance(item, QSpacerItem):
99 LayoutUtil.clear_layout(item.layout())
102 layout.removeItem(item)
def alternate_color(list_widgets, colors_alter=[Qt.white, Qt, gray)