I need some help on how to highlight a specific word in a QTableWidget cell. For example in this image. Let's say I want to highlight the word "James" color green. There are words "James" that are full words and those who aren't so still I needed them to be highlighted
Now take note I have already searched about this and I found this similar solution and I studied on it (It's actually cool!). How to highlight a words in QTableWidget from a Searchlist. But seems that there are some parts that are different on my goal and quite complicated and mine is very very simple. Just like that when the table has its data it will highlight a chosen word, I believe this can be done easily with in a shorter code or much simpler way to implement the coloring of a word. Please I need some help I find this really awesome and looking forward to accomplish this.
Let's take this sample code with a simple PYQT5 QTableWidget for a test.
import sys
from PyQt5.QtWidgets import *
#Main Window
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'PyQt5 - QTableWidget'
self.left = 0
self.top = 0
self.width = 300
self.height = 200
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.createTable()
self.layout = QVBoxLayout()
self.layout.addWidget(self.tableWidget)
self.setLayout(self.layout)
#Show window
self.show()
#Create table
def createTable(self):
self.tableWidget = QTableWidget()
#Row count
self.tableWidget.setRowCount(4)
#Column count
self.tableWidget.setColumnCount(2)
self.tableWidget.setItem(0,0, QTableWidgetItem("Name"))
self.tableWidget.setItem(0,1, QTableWidgetItem("City"))
self.tableWidget.setItem(1,0, QTableWidgetItem("Lebron James"))
self.tableWidget.setItem(1,1, QTableWidgetItem("King James"))
self.tableWidget.setItem(2,0, QTableWidgetItem("KingJames"))
self.tableWidget.setItem(2,1, QTableWidgetItem("Champions"))
self.tableWidget.setItem(3,0, QTableWidgetItem("World"))
self.tableWidget.setItem(3,1, QTableWidgetItem("2020"))
#Table will fit the screen horizontally
self.tableWidget.horizontalHeader().setStretchLastSection(True)
self.tableWidget.horizontalHeader().setSectionResizeMode(
QHeaderView.Stretch)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())