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 disable a qlistwidget item in Qt C++
Forum Updated to NodeBB v4.3 + New Features

How to disable a qlistwidget item in Qt C++

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 9.1k Views 2 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.
  • mrjjM mrjj

    Hi
    You can make it not select able
    item->setFlags(item->flags() & ~Qt::ItemIsSelectable);

    M Offline
    M Offline
    moyin
    wrote on last edited by
    #4

    @mrjj
    hi thanks for rply, i tried as u suggested but doesn't make sense.

    ui->listWidget_CPUs->item(0)->setFlags( ui->listWidget_CPUs->item(0)->flags() & ~Qt::ItemIsSelectable);
    
    D mrjjM 2 Replies Last reply
    0
    • M moyin

      @mrjj
      hi thanks for rply, i tried as u suggested but doesn't make sense.

      ui->listWidget_CPUs->item(0)->setFlags( ui->listWidget_CPUs->item(0)->flags() & ~Qt::ItemIsSelectable);
      
      D Offline
      D Offline
      Devopia53
      wrote on last edited by
      #5

      @moyin

      If so, what @Paul-Colby already proposed is what you want.

      1 Reply Last reply
      0
      • M moyin

        @mrjj
        hi thanks for rply, i tried as u suggested but doesn't make sense.

        ui->listWidget_CPUs->item(0)->setFlags( ui->listWidget_CPUs->item(0)->flags() & ~Qt::ItemIsSelectable);
        
        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @moyin

        In what way "doesn't make sense." ?

        1 Reply Last reply
        0
        • Paul ColbyP Paul Colby

          Hi @moyin,

          Not sure, but perhaps something like:

          QListWidgetItem * item = listWidget->item(row); // Or some other way to get the item in question.
          item->setFlags(item->flags() & ~Qt::ItemIsEnabled); // Remove the group of ItemIsEnabled flags.
          

          Cheers.

          Edit: Ah, @mrjj beat me to it ;)

          M Offline
          M Offline
          moyin
          wrote on last edited by
          #7

          @Paul-Colby,Hi thanks for reply,
          how to re-enable it back after disabling bcoz the above code will disable permanantly, i need to enable back it again.

          mrjjM 1 Reply Last reply
          0
          • M moyin

            @Paul-Colby,Hi thanks for reply,
            how to re-enable it back after disabling bcoz the above code will disable permanantly, i need to enable back it again.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #8

            @moyin

            Hi just remove the
            ~
            item->setFlags(item->flags() & Qt::ItemIsEnabled);

            JonBJ 1 Reply Last reply
            0
            • mrjjM mrjj

              @moyin

              Hi just remove the
              ~
              item->setFlags(item->flags() & Qt::ItemIsEnabled);

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #9

              @mrjj , @Paul-Colby
              That won't work, I think, once the flags have been set. He'll want:

              ui->listWidget_CPUs->item(0)->setFlags( ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable);

              M 1 Reply Last reply
              0
              • JonBJ JonB

                @mrjj , @Paul-Colby
                That won't work, I think, once the flags have been set. He'll want:

                ui->listWidget_CPUs->item(0)->setFlags( ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable);

                M Offline
                M Offline
                moyin
                wrote on last edited by
                #10

                @JonB @mrjj , @Paul-Colby
                I tried this

                ui->listWidget_CPUs->item(0)->setFlags( ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable);
                

                doesn't working, i want to enable it again after disabling.

                D JonBJ 2 Replies Last reply
                0
                • M moyin

                  @JonB @mrjj , @Paul-Colby
                  I tried this

                  ui->listWidget_CPUs->item(0)->setFlags( ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable);
                  

                  doesn't working, i want to enable it again after disabling.

                  D Offline
                  D Offline
                  Devopia53
                  wrote on last edited by Devopia53
                  #11

                  @moyin

                  You can try this:
                  ui->listWidget_CPUs->item(0)->setFlags(ui->listWidget_CPUs->item(0)->flags() ^ Qt::ItemIsEnabled); // both enable or disable, toggle mode

                  1 Reply Last reply
                  2
                  • M moyin

                    @JonB @mrjj , @Paul-Colby
                    I tried this

                    ui->listWidget_CPUs->item(0)->setFlags( ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable);
                    

                    doesn't working, i want to enable it again after disabling.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #12

                    @moyin
                    Well, if ui->listWidget_CPUs->item(0)->flags() & ~Qt::ItemIsSelectable disables it, then ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable undoes the effect of the first statement....

                    I suppose you could try ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable | Qt::ItemIsEnabled, but I don't see why you should have to.

                    M 1 Reply Last reply
                    2
                    • JonBJ JonB

                      @moyin
                      Well, if ui->listWidget_CPUs->item(0)->flags() & ~Qt::ItemIsSelectable disables it, then ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable undoes the effect of the first statement....

                      I suppose you could try ui->listWidget_CPUs->item(0)->flags() | Qt::ItemIsSelectable | Qt::ItemIsEnabled, but I don't see why you should have to.

                      M Offline
                      M Offline
                      moyin
                      wrote on last edited by
                      #13

                      @JonB yes! it works fine thank you,

                      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