Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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

  • Lifetime Qt Champion

    Hi,

    Isn't that mostly the same question as here ?



  • Can any one help me here


  • Lifetime Qt Champion

    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.



  • 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

  • Lifetime Qt Champion

    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.



  • @SGaist

    Iit is legacy code and I can't change that


  • Lifetime Qt Champion

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



  • We have edit that


Log in to reply