QLineEdit のパレットを使用して、QGradient を背景色として割り当てることができます。
line = QtGui.QLineEdit()
palette = line.palette()
QRectF = QtCore.QRectF(line.rect())
gradient = QtGui.QLinearGradient(QRectF.topLeft(), QRectF.topRight())
palette.setBrush(QtGui.QPalette.Base, QtGui.QBrush(gradient))
line.setPalette(palette)
line.show()
で作業している間QTableView
、私はすべてのリクエストに対してモデルのメソッドからQAbstractTableModel
ソリッドを返します。無地の色の代わりに、tableViewの「アイテム」にグラデーションを割り当てたいと思います。単色の代わりにグラデーションを割り当てる方法は?QColor
data
BackgroundColorRole
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
class Model(QtCore.QAbstractTableModel):
def __init__(self):
QtCore.QAbstractTableModel.__init__(self)
self.items = [[1, 'one', 'ONE'], [2, 'two', 'TWO'], [3, 'three', 'THREE']]
def rowCount(self, parent=QtCore.QModelIndex()):
return 3
def columnCount(self, parent=QtCore.QModelIndex()):
return 3
def data(self, index, role):
if not index.isValid(): return
if role in [QtCore.Qt.DisplayRole, QtCore.Qt.EditRole]:
return self.items[index.row()][index.column()]
if role == QtCore.Qt.ForegroundRole:
return QtGui.QColor("white")
if role == QtCore.Qt.BackgroundColorRole:
return QtGui.QColor("gray")
def onClick(index):
print 'clicked index: %s'%index
tableModel=Model()
tableView=QtGui.QTableView()
tableView.setModel(tableModel)
tableView.clicked.connect(onClick)
tableView.show()
app.exec_()