Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to show cursor in a particular cell of QTableWidget in pyQt
Forum Updated to NodeBB v4.3 + New Features

how to show cursor in a particular cell of QTableWidget in pyQt

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 1.7k Views 2 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by Qt Enthusiast
    #1

    I am using following PyQt code and The requirement the cursor should blink at the start of cell 0,1

       import sys 
       from PyQt4.QtCore import *
       from PyQt4.QtGui import *
    
       data = {'col1':['1','2','3'], 'col2':['4','5','6'], 'col3':['7','8','9']}
    
        class MyTable(QTableWidget):
           def __init__(self, data, *args):
               QTableWidget.__init__(self, *args)
               self.data = data
               self.setmydata()
               self.resizeColumnsToContents()
               self.resizeRowsToContents()
                self.setCursorPosition()
    
    
            def setmydata(self):
    
                horHeaders = []
                for n, key in enumerate(sorted(self.data.keys())):
                    horHeaders.append(key)
                    for m, item in enumerate(self.data[key]):
                      newitem = QWidget()
                      self.setCellWidget(m, n, newitem)
                      self.setHorizontalHeaderLabels(horHeaders)
    
            def setCursorPosition(self):
                 wid = self.cellWidget(0,1)
                 wid.setCursor(QCursor(Qt.WaitCursor))
                 wid.setFocus()
                
    
           The requirement is to blink the cursor at the start of cell  0,1. The lines in method setCursorPosition does not help me  . Can some one help me with the solution
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Isn't that mostly the same question as here ?

      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
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        Can any one help me here

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're putting an empty widget here so there's no sense in putting a cursor there.

          What's the goal of the widget ?

          Again, it's seems a duplicate of your other thread.

          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
          0
          • Q Offline
            Q Offline
            Qt Enthusiast
            wrote on last edited by
            #5

            This is my Example , Actually it QTextBrowser and the goal of the project is to when user does an action , the cursor should blink at start of Qtextbrower

            import sys
            from PyQt4.QtCore import *
            from PyQt4.QtGui import *

            data = {'col1':['1','2','3'], 'col2':['4','5','6'], 'col3':['7','8','9']}

            class MyTable(QTableWidget):
               def __init__(self, data, *args):
                   QTableWidget.__init__(self, *args)
                   self.data = data
                   self.setmydata()
                   self.resizeColumnsToContents()
                   self.resizeRowsToContents()
                    self.setCursorPosition()
            
            
                def setmydata(self):
            
                    horHeaders = []
                    for n, key in enumerate(sorted(self.data.keys())):
                        horHeaders.append(key)
                        for m, item in enumerate(self.data[key]):
                          newitem = QTextBrowser()
                          newitem.setText("text")
                          self.setCellWidget(m, n, newitem)
                          self.setHorizontalHeaderLabels(horHeaders)
            
                def setCursorPosition(self):
                     wid = self.cellWidget(0,1)
                     wid.setCursor(QCursor(Qt.WaitCursor))
                     wid.setFocus()
                    
            
               The requirement is to blink the cursor at the start of cell  0,1. The lines in method setCursorPosition does not help me  . Can some one help me with the solution
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Again, why are you using QTextBrowser in a cell to show text data ?

              If you want to use it as an editor, make a custom QStyledItemDelegate for that. Based on your code, there's no reason to use a cell widget.

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

              Q 1 Reply Last reply
              0
              • SGaistS SGaist

                Again, why are you using QTextBrowser in a cell to show text data ?

                If you want to use it as an editor, make a custom QStyledItemDelegate for that. Based on your code, there's no reason to use a cell widget.

                Q Offline
                Q Offline
                Qt Enthusiast
                wrote on last edited by
                #7

                @SGaist

                Iit is legacy code and I can't change that

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You do realize that QTextBrowser is a read-only widget ?

                  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
                  1
                  • Q Offline
                    Q Offline
                    Qt Enthusiast
                    wrote on last edited by
                    #9

                    We have edit that

                    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 Extensions
                    • Unsolved