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 set QTableWidget editable with a few non-editable columns, and editing by one click on cell?
QtWS25 Last Chance

How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 4 Posters 4.7k 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.
  • K Kuji

    @JonB Added, when i choose cell which is non-editable console writes:
    In slot
    Calling edit()
    edit: editing failed
    Called edit()

    When i choose editable cells console writes:
    In slot
    Calling edit()
    Called edit()

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

    @Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:

    @JonB Added, when i choose cell which is non-editable console writes:

    I did not realize you were doing this on the non-editable cells! So it is behaving well/as it should, what is the issue? Earlier you wrote:

    but when i click on enabled cell in console appears line "edit: editing failed"

    Now you show that works fine on editable cells.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kuji
      wrote on last edited by
      #8

      How can i get rid of lines in console:edit: editing failed? By don't calling edit() for these cells then how exclude these cells?

      JonBJ 1 Reply Last reply
      0
      • K Kuji

        How can i get rid of lines in console:edit: editing failed? By don't calling edit() for these cells then how exclude these cells?

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

        @Kuji

        if (ui->tableWidgetAdminEmployee->itemFromIndex(index)->flags() & Qt::ItemIsEnabled )
            ui->tableWidgetAdminEmployee->edit(index);
        

        Something like that.

        K 1 Reply Last reply
        0
        • JonBJ JonB

          @Kuji

          if (ui->tableWidgetAdminEmployee->itemFromIndex(index)->flags() & Qt::ItemIsEnabled )
              ui->tableWidgetAdminEmployee->edit(index);
          

          Something like that.

          K Offline
          K Offline
          Kuji
          wrote on last edited by Kuji
          #10

          @JonB Can't write instead of this code line because of en error, or i should write this in another place?

          ui->tableWidgetAdminEmployee->edit(index);
          
          Christian EhrlicherC 1 Reply Last reply
          0
          • K Kuji

            @JonB Can't write instead of this code line because of en error, or i should write this in another place?

            ui->tableWidgetAdminEmployee->edit(index);
            
            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #11

            @Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:

            Can't write instead of this code line because of en error,

            Then fixing the error would be a good start.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            K 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:

              Can't write instead of this code line because of en error,

              Then fixing the error would be a good start.

              K Offline
              K Offline
              Kuji
              wrote on last edited by
              #12

              @Christian-Ehrlicher i mean this error

              error: 'itemFromIndex' is a protected member of 'QTableWidget'
              

              here

                  QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
                                       ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) {
                          ui->tableWidgetAdminEmployee->setCurrentIndex(index);
                          if (ui->tableWidgetAdminEmployee->itemFromIndex(index)->flags() & Qt::ItemIsEnabled )
                              ui->tableWidgetAdminEmployee->edit(index);
                          });
              
              1 Reply Last reply
              0
              • M Offline
                M Offline
                mpergand
                wrote on last edited by
                #13

                try:
                ui->tableWidgetAdminEmployee->item(index.row(), index.column())

                K 1 Reply Last reply
                1
                • M mpergand

                  try:
                  ui->tableWidgetAdminEmployee->item(index.row(), index.column())

                  K Offline
                  K Offline
                  Kuji
                  wrote on last edited by Kuji
                  #14

                  @mpergand This worked

                  QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
                            ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) {
                  ui->tableWidgetAdminEmployee->setCurrentIndex(index);
                  if(index.column()!=0&&index.column()!=7&&index.column()!=8&&index.column()!=9)
                  if (ui->tableWidgetAdminEmployee->item(index.row(), index.column())->flags() & Qt::ItemIsEnabled )
                  ui->tableWidgetAdminEmployee->edit(index);
                  });
                  

                  But now after making some columns editable i can't make them non-editable

                  M 1 Reply Last reply
                  0
                  • K Kuji

                    @mpergand This worked

                    QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
                              ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) {
                    ui->tableWidgetAdminEmployee->setCurrentIndex(index);
                    if(index.column()!=0&&index.column()!=7&&index.column()!=8&&index.column()!=9)
                    if (ui->tableWidgetAdminEmployee->item(index.row(), index.column())->flags() & Qt::ItemIsEnabled )
                    ui->tableWidgetAdminEmployee->edit(index);
                    });
                    

                    But now after making some columns editable i can't make them non-editable

                    M Offline
                    M Offline
                    mpergand
                    wrote on last edited by
                    #15

                    @Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:

                    But now after making some columns editable i can't make them non-editable

                    Change the flag of the item accordingly.

                    K 1 Reply Last reply
                    0
                    • M mpergand

                      @Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:

                      But now after making some columns editable i can't make them non-editable

                      Change the flag of the item accordingly.

                      K Offline
                      K Offline
                      Kuji
                      wrote on last edited by Kuji
                      #16

                      @mpergand I tryed this, but after clicking on the cell it's editable and then it becomes unselectable

                          QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
                                           ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) {
                              ui->tableWidgetAdminEmployee->setCurrentIndex(index);
                              ui->tableWidgetAdminEmployee->item(index.row(), index.column())->setFlags(Qt::ItemIsSelectable);
                          });
                      
                      M 1 Reply Last reply
                      0
                      • K Kuji

                        @mpergand I tryed this, but after clicking on the cell it's editable and then it becomes unselectable

                            QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
                                             ui->tableWidgetAdminEmployee, [=](const QModelIndex& index) {
                                ui->tableWidgetAdminEmployee->setCurrentIndex(index);
                                ui->tableWidgetAdminEmployee->item(index.row(), index.column())->setFlags(Qt::ItemIsSelectable);
                            });
                        
                        M Offline
                        M Offline
                        mpergand
                        wrote on last edited by
                        #17

                        @Kuji
                        Qt::ItemIsSelectable|Qt::ItemIsEnabled

                        K 1 Reply Last reply
                        0
                        • M mpergand

                          @Kuji
                          Qt::ItemIsSelectable|Qt::ItemIsEnabled

                          K Offline
                          K Offline
                          Kuji
                          wrote on last edited by
                          #18

                          @mpergand cells are editable when i click on them and after that they are non-editable but write "edit: editing failed" in console

                          M 1 Reply Last reply
                          0
                          • K Kuji

                            @mpergand cells are editable when i click on them and after that they are non-editable but write "edit: editing failed" in console

                            M Offline
                            M Offline
                            mpergand
                            wrote on last edited by
                            #19

                            @Kuji
                            To tell the truth, i don't understand what you're trying to do from the beginning.

                            K 1 Reply Last reply
                            0
                            • M mpergand

                              @Kuji
                              To tell the truth, i don't understand what you're trying to do from the beginning.

                              K Offline
                              K Offline
                              Kuji
                              wrote on last edited by Kuji
                              #20

                              @mpergand I'm trying by pressing the button make editable some columns and make non-editable some columns in table, then after another button make all table non-editable.
                              Also i can't disconnect, if i could i would just set table readonly

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mpergand
                                wrote on last edited by
                                #21

                                QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,

                                Here you click on a table cell not on a button.
                                So what button are you talking about ?

                                K 1 Reply Last reply
                                0
                                • M mpergand

                                  QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,

                                  Here you click on a table cell not on a button.
                                  So what button are you talking about ?

                                  K Offline
                                  K Offline
                                  Kuji
                                  wrote on last edited by
                                  #22

                                  @mpergand this connection happens after pressing on usuall QPushButton

                                  M 1 Reply Last reply
                                  0
                                  • K Kuji

                                    @mpergand this connection happens after pressing on usuall QPushButton

                                    M Offline
                                    M Offline
                                    mpergand
                                    wrote on last edited by
                                    #23

                                    @Kuji said in How to set QTableWidget editable with a few non-editable columns, and editing by one click on cell?:

                                    @mpergand this connection happens after pressing on usuall QPushButton

                                    Where do you make this connection, where is that button, outside or inside the table ?
                                    QObject::connect(ui->tableWidgetAdminEmployee, &QTableWidget::clicked,
                                    doesn't respond to a button click.

                                    1 Reply Last reply
                                    0
                                    • K Offline
                                      K Offline
                                      Kuji
                                      wrote on last edited by Kuji
                                      #24

                                      Done by disconnecting to set all non-editable

                                          QObject::disconnect(ui->tableWidgetAdminEmployee,nullptr,nullptr,nullptr);
                                          ui->tableWidgetAdminEmployee->setEditTriggers(QAbstractItemView::NoEditTriggers);
                                      

                                      and connect if want to make any columns editable or non-editable where editing works by one click

                                      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