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. Change cell contents before editing QTableWidget cell?

Change cell contents before editing QTableWidget cell?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 191 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.
  • P Offline
    P Offline
    Publicnamer
    wrote on last edited by
    #1

    If the user double-clicks on a cell, it is the current contents of the cell that are what is used in the editing box within that cell.

    Is there a way for me to replace the text in the cell just after the double click and just before the cell enters editing mode?

    eyllanescE 1 Reply Last reply
    0
    • P Publicnamer

      If the user double-clicks on a cell, it is the current contents of the cell that are what is used in the editing box within that cell.

      Is there a way for me to replace the text in the cell just after the double click and just before the cell enters editing mode?

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @Publicnamer Use a delegate:

      class Delegate: public QStyledItemDelegate{
      public:
          using QStyledItemDelegate::QStyledItemDelegate;
          void setEditorData(QWidget *editor, const QModelIndex &index) const{
              if(QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor)){
                  lineEdit->setText("Foo");
              }
          }
      };
      
      tableWidget->setItemDelegate(new Delegate);
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      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