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. [SOLVED] Checkboxes in QListWidget appear as locked
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Checkboxes in QListWidget appear as locked

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 4.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.
  • T Offline
    T Offline
    Thegreger
    wrote on last edited by
    #1

    Hi everybody,

    I'm quite new to Qt, with a few months of experience.

    I'm currently working with a project that contains a QListWidget, mainly because it's an easy solution to create lists of slightly more complex widgets. I'm trying to give each new list item a checkbox. In my current code, this is done by:

    @ListFrame *frame1 = new ListFrame(this);
    QListWidgetItem *item = new QListWidgetItem();
    item->setCheckState(Qt::Checked);
    item->setFlags(item->flags() | Qt::ItemIsUserCheckable);

    ui->listWidget->addItem(item);
    ui->listWidget->setItemWidget(item,frame1);@

    My ListFrame class is simply a frame with a number of labels in it.
    If I omit the "Qt::ItemIsUserCheckable" flag, the checkbox in my list is greyed out. With the flag, however, the checkbox is not greyed out, but it's still behaving as though it were disabled! I've tried clicking the frame that is my item, the labels that it contains, or the checkbox itself, and it never changes state. Note that this problem persists even if I use a standard class such as QLabel instead of my ListFrame.

    Have I misunderstood something? According to all other info I've found, it should be enough to add the flag ItemIsUserCheckable and set a checked or unchecked state.

    Thanks for any help!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Thegreger
      wrote on last edited by
      #2

      Found it!
      http://developer.nokia.com/Community/Wiki/Archived:QListWidget_with_checkbox

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

        Hi,

        Great you found out and shared the solution !

        Can you also update the thread title prepending [solved] so other forum users may know a solution 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
        • T Offline
          T Offline
          Thegreger
          wrote on last edited by
          #4

          Oh, right. I was looking for a "Solved" button somewhere. Done! :D

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sateesh
            wrote on last edited by
            #5

            Hi ,
            Working on similar issue and got the same problem.
            Help will be Appreciated.

            mrjjM 1 Reply Last reply
            0
            • S sateesh

              Hi ,
              Working on similar issue and got the same problem.
              Help will be Appreciated.

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

              @sateesh
              Hi and welcome to the forums.
              Make sure you keep the default item flags when you set checkable

                QListWidgetItem* item = new QListWidgetItem("myitem", ui->listWidget);
                  item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set the checkable flag
                  item->setCheckState(Qt::Unchecked); // also initialize check state
              
              

              alt text

              S 1 Reply Last reply
              1
              • mrjjM mrjj

                @sateesh
                Hi and welcome to the forums.
                Make sure you keep the default item flags when you set checkable

                  QListWidgetItem* item = new QListWidgetItem("myitem", ui->listWidget);
                    item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set the checkable flag
                    item->setCheckState(Qt::Unchecked); // also initialize check state
                
                

                alt text

                S Offline
                S Offline
                sateesh
                wrote on last edited by
                #7

                @mrjj

                Firstly, Thanks for the reply.
                sorry for not mentioning the problem clearly.

                I have an QListWidgetItem and need to make the text editable. so used QLineEdit as itemwidget.

                QLineEdit *lineEditStructureName = new QLineEdit();
                lineEditStructureName->setText(structureName);
                lineEditStructureName->setFocusPolicy(Qt::ClickFocus);
                //listWidgetItem->setSizeHint (lineEditStructureName->sizeHint ());
                this->ui->listWidgetStructures->setItemWidget (listWidgetItem, lineEditStructureName);

                Now the problem is Not getting accessed. as the links description its kind of locked.
                Is there anything I'm doing wrong ?

                jsulmJ 1 Reply Last reply
                0
                • S sateesh

                  @mrjj

                  Firstly, Thanks for the reply.
                  sorry for not mentioning the problem clearly.

                  I have an QListWidgetItem and need to make the text editable. so used QLineEdit as itemwidget.

                  QLineEdit *lineEditStructureName = new QLineEdit();
                  lineEditStructureName->setText(structureName);
                  lineEditStructureName->setFocusPolicy(Qt::ClickFocus);
                  //listWidgetItem->setSizeHint (lineEditStructureName->sizeHint ());
                  this->ui->listWidgetStructures->setItemWidget (listWidgetItem, lineEditStructureName);

                  Now the problem is Not getting accessed. as the links description its kind of locked.
                  Is there anything I'm doing wrong ?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @sateesh Set Qt::ItemIsEditable flag on your item.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1

                  • Login

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