Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QPainter won't draw lines on QTableWidget
ACollins last edited by ACollins
I have a table which I defined this way.
def setupUi(self, Dialog): Dialog.setObjectName("Dialogs") x = 450 y = 1394 posX = 1005 Dialog.resize(x, y) Dialog.setMinimumSize(QtCore.QSize(x, y)) Dialog.setMaximumSize(QtCore.QSize(x, y)) Dialog.setGeometry(QtCore.QRect(posX, 0, x, y)) Dialog.setStyleSheet("background-color: rgb(172,216,219);") self.tableWidget = QtWidgets.QTableWidget(Dialog) self.tableWidget.setGeometry(QtCore.QRect(0, 0, x-1, y-1)) self.tableWidget.setObjectName("tableWidget")
Everything works fine with the table but then I try to put a line on the table, which later on will be dynamic, nothing shows up. I was able to use this code in a standalone app and it worked but when I try to draw on QTableWidget nothing shows up. Thanks.
self.painter = QtGui.QPainter(Dialog) self.painter.begin(Dialog) self.painter.setRenderHint(QPainter.Antialiasing) self.painter.setPen(QtCore.Qt.red) self.painter.setBrush(QtCore.Qt.white) self.painter.drawLine(40, 1050, 60, 1100)
Where did you put that code ?
You can't arbitrarily paint on a widget. It has to happens in it's paintEvent method.
ACollins last edited by
Just below where i created the table and certainly not in paintEvent method. I see some examples online so will try those out. Thanks.