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. TableWidget cell highlights sometimes and other times doesn't. Two cell widget types.
Forum Updated to NodeBB v4.3 + New Features

TableWidget cell highlights sometimes and other times doesn't. Two cell widget types.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 661 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.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by
    #1
    class TranslationEditor(QMainWindow, Ui_TranslationEditor):
        def __init__(self):
            super().__init__()
            super().__init__()
            self.setupUi(self)
    
            self.addRow()
            
        def returnPressed(self):
            self.addRow()
            self.transTable.cellWidget(self.transTable.rowCount() - 1, 0).setFocus()
    
        def addRow(self):
            row_count = self.transTable.rowCount()
            byte_seq_line = self.createLineEdit()
            byte_seq_line.setValidator(HexStringValidator())
            byte_seq_line.returnPressed.connect(self.returnPressed)
            
            loc_widget = NibbleLocationWidget()
            trans_line = self.createLineEdit()
            trans_line.returnPressed.connect(self.returnPressed)
            comment_line = self.createLineEdit()
            comment_line.returnPressed.connect(self.returnPressed)
            
            self.setTabOrders([byte_seq_line, loc_widget, trans_line, comment_line])
            
            self.transTable.setRowCount(row_count + 1)
            self.transTable.setCellWidget(row_count, 0, byte_seq_line)
            self.transTable.setCellWidget(row_count, 1, loc_widget)
            self.transTable.setCellWidget(row_count, 3, comment_line)
        
        def setTabOrders(self, widgets):
            for k in range(len(widgets) - 1):
                self.setTabOrder(widgets[k], widgets[k+1])
    
        @staticmethod
        def createLineEdit():
            line_edit = QLineEdit()
            line_edit.setFrame(False)
            return line_edit
    

    Result:

    Opening translation editor:
    alt text

    Pressing tab key once:
    alt text

    Pressing tab key again:
    alt text

    And one last tab key press:
    alt text

    Obviously, I can't release a professional app if it's doing this. Any idea how to get the field highlighting to consistently be like the 1st and 4th cells when entered?

    Each cell except for nibble location has a QLineEdit (see code).

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    1 Reply Last reply
    0
    • enjoysmathE Offline
      enjoysmathE Offline
      enjoysmath
      wrote on last edited by
      #2

      I'll try taking out the spinbox and just using a validated lineedit. Should work.

      https://github.com/enjoysmath
      https://math.stackexchange.com/users/26327/exercisingmathematician

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        Or just do the right thing and use a delegate (QStyledItemDelegate subclass) for the columns instead of setCellWidget

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2

        • Login

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