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. QTableWidget: scrolling causes data loss

QTableWidget: scrolling causes data loss

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 312 Views
  • 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.
  • C Offline
    C Offline
    clarify
    wrote on last edited by clarify
    #1

    I've put a QLineEdit into a table cell.
    When the user is editing in that line edit, if he scrolls with the mouse wheel, the data in the line edit is lost.
    How can this be prevented?

    In addition, if I try to read out the data from the line editor, e.g. by obtaining the item for the cell that was being edited, I get a null pointer:

    QTableWidgetItem *item = table->itemAt(row, column);
    if (item==NULL) { uh oh }
    
    JonBJ 1 Reply Last reply
    0
    • C clarify

      I've put a QLineEdit into a table cell.
      When the user is editing in that line edit, if he scrolls with the mouse wheel, the data in the line edit is lost.
      How can this be prevented?

      In addition, if I try to read out the data from the line editor, e.g. by obtaining the item for the cell that was being edited, I get a null pointer:

      QTableWidgetItem *item = table->itemAt(row, column);
      if (item==NULL) { uh oh }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @clarify said in QTableWidget: scrolling causes data loss:

      I've put a QLineEdit into a table cell.

      With what code?

      C 1 Reply Last reply
      0
      • JonBJ JonB

        @clarify said in QTableWidget: scrolling causes data loss:

        I've put a QLineEdit into a table cell.

        With what code?

        C Offline
        C Offline
        clarify
        wrote on last edited by
        #3

        @JonB

            editorDel = new EditorDelegate;
            table->setItemDelegate(editorDel);
        
        JonBJ 1 Reply Last reply
        0
        • C clarify

          @JonB

              editorDel = new EditorDelegate;
              table->setItemDelegate(editorDel);
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @clarify
          So if you are doing your own item delegate for editing you are responsible somewhere for creating the QTableWidgetItem returned by QTableWidgetItem *item = table->itemAt(row, column);.

          I don't know how mouse wheel behaves in a QLineEdit. I don't know whether the table widget or the line edit receives wheel events. And I don't know if there are any issues/gotchas here for a QTableWidget versus a QTableView.

          Try QTableWidget::setCellWidget() to set a QLineEdit and compare how that behaves to your delegate.

          C 1 Reply Last reply
          0
          • JonBJ JonB

            @clarify
            So if you are doing your own item delegate for editing you are responsible somewhere for creating the QTableWidgetItem returned by QTableWidgetItem *item = table->itemAt(row, column);.

            I don't know how mouse wheel behaves in a QLineEdit. I don't know whether the table widget or the line edit receives wheel events. And I don't know if there are any issues/gotchas here for a QTableWidget versus a QTableView.

            Try QTableWidget::setCellWidget() to set a QLineEdit and compare how that behaves to your delegate.

            C Offline
            C Offline
            clarify
            wrote on last edited by
            #5

            @JonB I think I originally tried that, but it didn't work and people recommended using the delegate approach. The use of a delegate for this always seemed unseemly. The life cycle of the editor was hidden behind it and I had to just take it on faith that it would work well but it really hasn't.

            JonBJ 1 Reply Last reply
            0
            • C clarify

              @JonB I think I originally tried that, but it didn't work and people recommended using the delegate approach. The use of a delegate for this always seemed unseemly. The life cycle of the editor was hidden behind it and I had to just take it on faith that it would work well but it really hasn't.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @clarify said in QTableWidget: scrolling causes data loss:

              and people recommended using the delegate approach.

              I never said otherwise. That is preferable. What I suggested is you compare your delegate implementation's behaviour against what happens with setCellWidget(). If that gets it "right" you can always look at source code as to why.

              In addition, if I try to read out the data from the line editor, e.g. by obtaining the item for the cell that was being edited, I get a null pointer:

              Where do you create the QTableWidgetItem?

              C 1 Reply Last reply
              0
              • JonBJ JonB

                @clarify said in QTableWidget: scrolling causes data loss:

                and people recommended using the delegate approach.

                I never said otherwise. That is preferable. What I suggested is you compare your delegate implementation's behaviour against what happens with setCellWidget(). If that gets it "right" you can always look at source code as to why.

                In addition, if I try to read out the data from the line editor, e.g. by obtaining the item for the cell that was being edited, I get a null pointer:

                Where do you create the QTableWidgetItem?

                C Offline
                C Offline
                clarify
                wrote on last edited by clarify
                #7

                @JonB I'm using the QTableWidgetItems that are automatically created by the table.

                OK just now I tried switching back to using setCellWidget and that seems to work just fine (in Qt 5).

                I also needed to respond to scrolling by saving the text that was entered. I had to keep a QString containing that and update it with every keystroke.

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