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. Do not understand the meaning of this statement...
Forum Updated to NodeBB v4.3 + New Features

Do not understand the meaning of this statement...

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.3k 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.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by aha_1980
    #1

    Hi!!

    Im wondering why it says "ItemIsEnabled" if this flag disables it...

    ui->myWidgetTableItem->setFlags(Qt::ItemFlag::ItemIsEnabled);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This flag does not disable it. From the documentation of ItemIsEnabled : The user can interact with the item.

      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
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Do note you use setFlags so if you only give it one flag it might have side effects
        Since you then clear out
        Qt::ItemIsSelectable 1 It can be selected.
        Qt::ItemIsEditable 2 It can be edited.

        "The ItemFlags type is a typedef for QFlags<ItemFlag>. It stores an OR combination of ItemFlag values."

        So make sure the other flags are still set if you want it to be selectable etc.

        You can do it as one liner but here is a more verbose example to show how it can
        be used.

        // set the item editable
        item = tableWidget->item(0, 0);
        flags = item->flags();
        flags |= Qt::ItemIsSelectable | Qt::ItemIsEditable; // set the flag
        item->setFlags(flags);
         
         
        // set the item non-editable (view only), but still selectable
        item = tableWidget->item(0, 0);
        flags = item->flags();
        flags |= Qt::ItemIsSelectable;
        flags &= ~Qt::ItemIsEditable; // reset/clear the flag
        item->setFlags(flags);
         
         
        // set the item non-editable (view only), and non-selectable
        item = tableWidget->item(0, 0);
        flags = item->flags();
        flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag
        item->setFlags(flags);
        
        1 Reply Last reply
        5
        • U Offline
          U Offline
          U7Development
          wrote on last edited by
          #4

          All clear.. thanks!

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Good !

            In that case, please mark the thread as solved using the "Topic Tools" button so that other forum users may know an answer has been found :-)

            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
            0
            • S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #6

              What @mrjj describes works, but it is also a little bit more complicated than it needs to be. With regular flags (usually defined by enums) this would be the only way. However, QFlags also provides a convenient setter function:

              item = tableWidget->item(0, 0);
              item->setFlags(item->flags().setFlag(Qt::ItemIsSelectable, true).setFlag(Qt::ItemIsEditable, false));
              

              This example would turn on Qt::ItemIsSelectable and turn off Qt::ItemIsEditable. Note that it is possible to chain these together as setFlags(...) immediately returns QFlags again.

              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