I have this table, and what I want is a few things:
When I click on a cell, I want the entire row from that cell's location to be highlighted,something white-ish, and for some function to be able to get all the values from all the columns for that row
I have colors for all the combobox items, but I want to be able to color the combobox background with the same color as the one I chose for the selected item, the colors in
painter.fillRect()
Non-divine code:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets,uic
from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton,QTableWidget,QStyledItemDelegate
class MyQComboBox(QtWidgets.QComboBox):
def __init__(self, scrollWidget=None, *args, **kwargs):
super(MyQComboBox, self).__init__(*args, **kwargs)
self.scrollWidget=scrollWidget
self.setFocusPolicy(QtCore.Qt.StrongFocus)
def wheelEvent(self, *args, **kwargs):
return
class StatusItemDelegate(QtWidgets.QStyledItemDelegate):
def __init__(self, parent=None):
QtWidgets.QStyledItemDelegate.__init__(self, parent=parent)
def paint(self, painter, option, index):
if index.row() == 0 :
if option.state & QtWidgets.QStyle.State_Selected: # highligh background if selected
painter.fillRect(option.rect, option.palette.highlight())
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(228, 221, 131))) # Initializing...
painter.restore()
elif index.row() == 1 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(185, 183, 159))) # Not Started
painter.restore()
elif index.row() == 2 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(65, 203, 53))) # Track
painter.restore()
elif index.row() == 3 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(38, 121, 31))) # Track Apporval
painter.restore()
elif index.row() == 4 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(31, 121, 104))) # For Solve
painter.restore()
elif index.row() == 5 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(48, 216, 226))) # Solve
painter.restore()
elif index.row() == 6 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(226, 167, 48))) # For GeoBuild
painter.restore()
elif index.row() == 7 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(226, 142, 48))) # GeoBuild
painter.restore()
elif index.row() == 8 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(243, 222, 108))) # For Rotomation
painter.restore()
elif index.row() == 9 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(243, 141, 108))) # Rotomation
painter.restore()
elif index.row() == 10 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(154, 76, 79))) # Waiting Assets
painter.restore()
elif index.row() == 11 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(76, 112, 154))) # For Packing
painter.restore()
elif index.row() == 12 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(53, 89, 201))) # Packing
painter.restore()
elif index.row() == 13 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(114, 228, 118))) # Preview
painter.restore()
elif index.row() == 14 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(178, 114, 228))) # Ready
painter.restore()
elif index.row() == 15 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(147, 169, 236))) # For Delivery
painter.restore()
elif index.row() == 16 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(81, 50, 199))) # Delivered
painter.restore()
elif index.row() == 17 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(84, 95, 239))) # Approved
painter.restore()
elif index.row() == 18 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(239, 84, 84))) # Cancelled
painter.restore()
elif index.row() == 19 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(98, 81, 81))) # On Hold
painter.restore()
elif index.row() == 20 :
painter.save()
painter.fillRect(option.rect, QtGui.QBrush(QtGui.QColor(98, 1, 1))) # Got Issue
painter.restore()
QtWidgets.QStyledItemDelegate.paint(self, painter, option, index)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.UI=uic.loadUi('VertigoCentral.ui', self)
self.show()
self.TYPE = ("UV","LD")
self.STATUS = ("Initializing ...","Not Started","Track","Track Approval",
"For Solving", "Solve", "For GeoBuild", "GeoBuild", "For Rotomation",
"Rotomation","Waiting Assets",
"For Packing", "Packing","Preview","Ready",
"For Delivery","Delivered","Approved",
"Cancelled","On Hold","Got Issue!")
app = QApplication(sys.argv)
window = MainWindow()
window.setFixedSize(1920, 1080)
for row in range(window.ShotTable.rowCount()):
window.ShotTable.setRowHeight(row,36)
scrollArea = QtWidgets.QScrollArea()
frmScroll = QtWidgets.QFrame(scrollArea)
cmbOption = MyQComboBox(frmScroll)
Status = cmbOption
Status.setObjectName("Status")
for index,it in enumerate(window.STATUS):
Status.addItem("")
Status.setItemText(index, it)
Status.setItemDelegate(StatusItemDelegate())
window.ShotTable.setCellWidget(row, 5, Status)
view = Status.view()
view.setFixedHeight(570)
window.ShotTable.setFocusPolicy(Qt.NoFocus)
window.show()
app.exec()