Created
November 8, 2021 22:20
-
-
Save anddam/23924192a6748a146ea054213a206255 to your computer and use it in GitHub Desktop.
PySide Qt issue with shifted chars in string when placing a TableWidgetItem in a TableWidget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide2.QtCore import Qt | |
from PySide2.QtWidgets import QMainWindow, QTableWidgetItem | |
class CMTableWidgetItemNonEditable(QTableWidgetItem): | |
"""Unset editing flags | |
""" | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.setFlags(self.flags() & ~Qt.ItemIsEditable) | |
class MainWindow(QMainWindow): | |
# ⋮ Lot of other stuff here | |
def update_table(self, data): | |
logger.debug("data=%r", data) | |
for row, (name, value) in enumerate(data.items()): | |
# Data come in bytes | |
name, value = name.decode("utf-8"), value.decode("utf-8") | |
self.readerInfoTable.insertRow(row) | |
item_1 = CMTableWidgetItemNonEditable(name) | |
item_2 = CMTableWidgetItemNonEditable(value) | |
self.readerInfoTable.setItem(row, 0, item_1) | |
self.readerInfoTable.setItem(row, 1, item_2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment