Reputation: 341
How to dynamically created button to set the blue color as in the Windows game Sapper? This is a part of code
self.buttons = []
for i in xrange(self.HeightOfField):
l=[]
for j in xrange(self.WidthOfField):
b=QtGui.QPushButton()
b.setFixedSize(40,30)
l.append(b)
self.gridLayout.addWidget(b, i, j)
self.gridLayout.setColumnMinimumWidth(j, 40)
self.buttons.append(l)
self.gridLayout.setRowMinimumHeight(i, 26)
Upvotes: 0
Views: 102
Reputation: 4510
For me, the easiest way to set the colour of a button would be to use a stylesheet using .setStyleSheet
.
b.setStyleSheet('background-color: blue;')
You can use RGB colours, but it's easier to use HTML keyword names. Take a look at this table from W3C.
Upvotes: 2