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?

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

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.1k 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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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
      3
      • mrjjM mrjj

        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 last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • A Aaron Kim

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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

          • Login

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