Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QPainter won't draw lines on QTableWidget
Qt 6.12 LTS is out! See what's new in the release blog

QPainter won't draw lines on QTableWidget

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 903 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ACollins
    wrote on last edited by ACollins
    #1

    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)
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Where did you put that code ?
      You can't arbitrarily paint on a widget. It has to happens in it's paintEvent method.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • A Offline
        A Offline
        ACollins
        wrote on last edited by
        #3

        Just below where i created the table and certainly not in paintEvent method. I see some examples online so will try those out. Thanks.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved