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

QTreeWidgetItem Disable | Enable

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 2 Posters 6.5k Views
  • 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.
  • Taz742T Offline
    Taz742T Offline
    Taz742
    wrote on last edited by Taz742
    #1

    How To Disable | Enable QTreeWidgetCurrentItem?

    void wdgMyTree::PauseSLOT()
    {
        QTreeWidgetItem * last = ui->treeWidget->currentItem();
    
        if (last == top) {
            return;
        }
       
        last->setDisabled( !last->isDisabled() );
    
        if (globalall->db.open()) {
    
            QSqlQuery qry;
                      qry.prepare("update Tree Set Pause = :value where UID = : uid");
                      qry.bindValue(":uid", mpuid[last]);
                      qry.bindValue(":value", last->isDisabled() ? 1 : 0);
                      qry.exec();
    
            globalall->db.close();
        }
    }
    

    When the item is turned off and the last item changes, I will not allow you to get involved.
    I can not stand on the disabled item.

    Do what you want.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Use setFlags

      Qt::NoItemFlags allows nothing on the item

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      Taz742T 1 Reply Last reply
      1
      • VRoninV VRonin

        Use setFlags

        Qt::NoItemFlags allows nothing on the item

        Taz742T Offline
        Taz742T Offline
        Taz742
        wrote on last edited by
        #3

        Hi. @VRonin
        Yes I use it.
        But when I disable the item and I move anothar item I can not go back To get involved.

        QTreeWidgetItem * last = ui->treeWidget->currentItem(); **!BLOCKED**
        

        Do what you want.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          If you ant to go back you can set the Qt::ItemIsSelectable flag

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          Taz742T 1 Reply Last reply
          0
          • VRoninV VRonin

            If you ant to go back you can set the Qt::ItemIsSelectable flag

            Taz742T Offline
            Taz742T Offline
            Taz742
            wrote on last edited by
            #5

            @VRonin

                QTreeWidgetItem * last = ui->treeWidget->currentItem();
            
                if (last == top) {
                    return;
                }
            
                last->setFlags(Qt::NoItemFlags);
            
                last->setFlags(Qt::ItemIsSelectable);
            
            

            it not work :X

            Do what you want.

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              Could you put down a quick bullet list with:

              • what you are doing in the GUI
              • what you expect to happen
              • what happens instead

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              Taz742T 2 Replies Last reply
              1
              • VRoninV VRonin

                Could you put down a quick bullet list with:

                • what you are doing in the GUI
                • what you expect to happen
                • what happens instead
                Taz742T Offline
                Taz742T Offline
                Taz742
                wrote on last edited by Taz742
                #7

                @VRonin
                I Disable Item
                alt text

                I move Another Item

                alt text
                I can not enable disabled item

                Do what you want.

                1 Reply Last reply
                0
                • VRoninV VRonin

                  Could you put down a quick bullet list with:

                  • what you are doing in the GUI
                  • what you expect to happen
                  • what happens instead
                  Taz742T Offline
                  Taz742T Offline
                  Taz742
                  wrote on last edited by
                  #8

                  @VRonin
                  I can not select disabled item, problem it is.

                  Do what you want.

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    What's the difference between an enabled and disabled item? just the colour of the text? Does the behaviour change between the two?

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    Taz742T 1 Reply Last reply
                    0
                    • VRoninV VRonin

                      What's the difference between an enabled and disabled item? just the colour of the text? Does the behaviour change between the two?

                      Taz742T Offline
                      Taz742T Offline
                      Taz742
                      wrote on last edited by
                      #10

                      @VRonin said in QTreeWidgetItem Disable | Enable:

                      What's the difference between an enabled and disabled item? just the colour of the text? Does the behaviour change between the two?

                      No.
                      If I'm turned on or off, I'll have to decide on the following steps.

                      Do what you want.

                      1 Reply Last reply
                      0
                      • VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by
                        #11

                        Then you are misusing setDisabled.

                        • set the a boolean in the Qt::UserRole (true when is disabled)
                          • if(last->data(Qt::UserRole).toBool()) last->setData(Qt::UserRole,QVariant()); else last->setData(Qt::UserRole,true);
                        • reimplement QStyledItemDelegate::paint to use it.
                          • starting from the original source: https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qstyleditemdelegate.cpp.html#_ZNK19QStyledItemDelegate5paintEP8QPainterRK20QStyleOptionViewItemRK11QModelIndex
                          • replace QStyledItemDelegatePrivate::widget(option); with option.widget;
                          • add if(index.data(Qt::UserRole).toBool()) option.state &= ~QStyle::State_Enabled; in the line below initStyleOption
                        • apply the delegate to the view
                          • in the constructor call ui->treeWidget->setItemDelegate(new MyDelegate(this));

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        Taz742T 1 Reply Last reply
                        2
                        • VRoninV VRonin

                          Then you are misusing setDisabled.

                          • set the a boolean in the Qt::UserRole (true when is disabled)
                            • if(last->data(Qt::UserRole).toBool()) last->setData(Qt::UserRole,QVariant()); else last->setData(Qt::UserRole,true);
                          • reimplement QStyledItemDelegate::paint to use it.
                            • starting from the original source: https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qstyleditemdelegate.cpp.html#_ZNK19QStyledItemDelegate5paintEP8QPainterRK20QStyleOptionViewItemRK11QModelIndex
                            • replace QStyledItemDelegatePrivate::widget(option); with option.widget;
                            • add if(index.data(Qt::UserRole).toBool()) option.state &= ~QStyle::State_Enabled; in the line below initStyleOption
                          • apply the delegate to the view
                            • in the constructor call ui->treeWidget->setItemDelegate(new MyDelegate(this));
                          Taz742T Offline
                          Taz742T Offline
                          Taz742
                          wrote on last edited by Taz742
                          #12

                          @VRonin
                          I'm not good enough to understand your words.
                          I will think of something else.

                          • last->SetChecked( Qt::Checked or Qt :: Unchecked ); // bla bla bla

                          • Or replace an icon.

                          Just to understand the user.

                          Do what you want.

                          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