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?
Forum Updated to NodeBB v4.3 + New Features

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 5.6k 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.
  • 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