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. Why does QTableWidgetItem setflags() trigger itemChanged() signal?
Forum Updated to NodeBB v4.3 + New Features

Why does QTableWidgetItem setflags() trigger itemChanged() signal?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 967 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.
  • A Offline
    A Offline
    Aaron Kim
    wrote on 18 Aug 2018, 11:02 last edited by Aaron Kim
    #1
    void Dialog::setRowDisable(QTableWidget* table, int row){
        for(int column = 0; column < table->columnCount(); ++column){
            auto item = table->item(row, column);
            item->setFlags(item->flags() & ~Qt::ItemIsEditable);
        }
    }
    

    This simple code makes me suffer from segmentation fault derived from infinite loop.
    0_1534590188963_capture.PNG
    I can not understand this situation because setting flag does not affect the data of QTableWidgetItem.
    Is it intended? If so, how can I prevent it from triggering the event?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 18 Aug 2018, 11:11 last edited by mrjj
      #2

      Hi
      Because you do change the item. :)
      Anyway, try
      setting

      void Dialog::setRowDisable(QTableWidget* table, int row){
         table->blockSignals(true);
          for(int column = 0; column < table->columnCount(); ++column){
              auto item = table->item(row, column);
              item->setFlags(item->flags() & ~Qt::ItemIsEditable);
          }
         table->blockSignals(false);
      }
      

      If that works as you want , have a look at
      https://doc.qt.io/qt-5/qsignalblocker.html

      Its a better way of doing the same.

      A 1 Reply Last reply 18 Aug 2018, 15:53
      3
      • M mrjj
        18 Aug 2018, 11:11

        Hi
        Because you do change the item. :)
        Anyway, try
        setting

        void Dialog::setRowDisable(QTableWidget* table, int row){
           table->blockSignals(true);
            for(int column = 0; column < table->columnCount(); ++column){
                auto item = table->item(row, column);
                item->setFlags(item->flags() & ~Qt::ItemIsEditable);
            }
           table->blockSignals(false);
        }
        

        If that works as you want , have a look at
        https://doc.qt.io/qt-5/qsignalblocker.html

        Its a better way of doing the same.

        A Offline
        A Offline
        Aaron Kim
        wrote on 18 Aug 2018, 15:53 last edited by
        #3

        @mrjj Oh, there is a blockSignal function in Qt. I was struggling with implementing it myself ;) Thanks!

        M 1 Reply Last reply 18 Aug 2018, 18:21
        0
        • A Aaron Kim
          18 Aug 2018, 15:53

          @mrjj Oh, there is a blockSignal function in Qt. I was struggling with implementing it myself ;) Thanks!

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 18 Aug 2018, 18:21 last edited by
          #4

          @Aaron-Kim
          yep :)
          qsignalblocker is a special scope handling class that ensure u dont miss
          a blockSignals(false); if code in between can bail out due to error.

          1 Reply Last reply
          0

          1/4

          18 Aug 2018, 11:02

          • Login

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