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 make qtablewidget Read only?**
Forum Updated to NodeBB v4.3 + New Features

**How to make qtablewidget Read only?**

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 30.7k Views 3 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.
  • V Offline
    V Offline
    vasu_gupta
    wrote on 28 Aug 2017, 05:55 last edited by
    #1

    I have introduces a table in my ui file ,now what I want is that during run time the table values can only change due to internal algorithm but user is unable to make any change or select any cell externally.

    How can I do that?

    i want that table should only update data/text via internal algorithm ,but once the text is updated that cell become accessible to external input

    QTableWidgetItem *itm = new QTableWidgetItem();
    
    itm->setFlags(itm->flags()^(Qt::ItemIsSelectable|Qt::ItemIsEditable));
    ui->tableWidget->setItem(i,j,itm);
    

    at this point user cant enter value externally,but once i do this:

    QTableWidgetItem *itm = new QTableWidgetItem();
    itm->setText("0.554");
    ui->tableWidget->setItem(2,3,itm);
    

    cell(2,3) becomes accessible to external input,how to avoid this thing??

    after browsing many people suggest to use noedittrigger but i am unable to understand how to use it and what it does

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 28 Aug 2017, 06:27 last edited by mrjj
      #2

      @vasu_gupta said in **How to make qtablewidget Read only?**:

      noedittrigger

      Hi
      It is
      pTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

      Normally you can press enter or F2? or double click to start editing a cell. this will disable that.

      V S 2 Replies Last reply 28 Aug 2017, 06:45
      6
      • M mrjj
        28 Aug 2017, 06:27

        @vasu_gupta said in **How to make qtablewidget Read only?**:

        noedittrigger

        Hi
        It is
        pTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

        Normally you can press enter or F2? or double click to start editing a cell. this will disable that.

        V Offline
        V Offline
        vasu_gupta
        wrote on 28 Aug 2017, 06:45 last edited by
        #3

        @mrjj so after this will i be able to change table data by algorithm without making it editable again

        M 1 Reply Last reply 28 Aug 2017, 06:57
        0
        • V vasu_gupta
          28 Aug 2017, 06:45

          @mrjj so after this will i be able to change table data by algorithm without making it editable again

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 28 Aug 2017, 06:57 last edited by mrjj
          #4

          @vasu_gupta
          It disables the users normal ways of start editing.

          It has nothing to do with the items as such.

          • ..,but once i do this:

          You must set the flag AGAIN when you create new item.
          That is why it becomes editable again. Its no longer the old item and
          hence its editable again/as normally.

          But why do you new it again ?
          You can just call setText on the existing.

          1 Reply Last reply
          4
          • F Offline
            F Offline
            frnklu20
            wrote on 2 Aug 2019, 20:33 last edited by
            #5

            But how can i disable editing in only the items that i want?

            1 Reply Last reply
            1
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 2 Aug 2019, 22:28 last edited by
              #6

              Hi,

              Use QTableWidget::setFlags for the items you want to have different capabilities.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • F Offline
                F Offline
                frnklu20
                wrote on 5 Aug 2019, 12:12 last edited by
                #7

                Hi,

                Vnom->setFlags(Qt::ItemIsEditable);
                

                like this?but i want it to not to be editable.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 5 Aug 2019, 12:30 last edited by
                  #8

                  Hi
                  Well more like
                  Vnom->setFlags( Vnom->flags() & ~Qt::ItemIsEditable);
                  To mask out the Edit Flag and keep rest.

                  1 Reply Last reply
                  6
                  • M mrjj
                    28 Aug 2017, 06:27

                    @vasu_gupta said in **How to make qtablewidget Read only?**:

                    noedittrigger

                    Hi
                    It is
                    pTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

                    Normally you can press enter or F2? or double click to start editing a cell. this will disable that.

                    S Offline
                    S Offline
                    sayan275
                    wrote on 20 Jun 2021, 14:24 last edited by
                    #9

                    @mrjj but setting it back to AllEditTriggers, is not allowing to edit tableview anymore.
                    Am I missing anything?

                    M 1 Reply Last reply 20 Jun 2021, 14:32
                    0
                    • S sayan275
                      20 Jun 2021, 14:24

                      @mrjj but setting it back to AllEditTriggers, is not allowing to edit tableview anymore.
                      Am I missing anything?

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 20 Jun 2021, 14:32 last edited by
                      #10

                      @sayan275

                      Hi
                      The trigger settings tell what keys can start editing. like from having to press a key to start editing to allTriggers ,
                      where you simply can start typing.

                      The flags, however, is per item and they are normally Selectable and editable.
                      So if you remove say editable, its not possible to edit it, regardless of what can trigger an edit.

                      1 Reply Last reply
                      3

                      • Login

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