×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    7

    Unhappy Can not remove Checkbox of QListWidgetItem

    i can use below code to display a checkbox of QListWidgetItem
    item = ui->listWidget->item(i);
    Qt::ItemFlags flags = item->flags();
    flags |= Qt::ItemIsUserCheckable;
    item->setFlags(flags);
    item->setCheckState(Qt::Unchecked);

    but I can not remove it with below code
    item = ui->listWidget->item(i);
    Qt::ItemFlags flags = item->flags();
    flags ^= Qt::ItemIsUserCheckable;
    item->setFlags(flags);

    i traced QStyledItemDelegate:: paint(), this issue seems to be a bug. i googled it, but no useful info.

  2. #2
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: Can not remove Checkbox of QListWidgetItem

    i can use below code to display a checkbox of QListWidgetItem
    item = ui->listWidget->item(i);
    Qt::ItemFlags flags = item->flags();
    flags |= Qt::ItemIsUserCheckable;
    item->setFlags(flags);
    item->setCheckState(Qt::Unchecked);
    In first code you are showing blank means unchecked or Off (Zero value )check box.

    but I can not remove it with below code
    item = ui->listWidget->item(i);
    Qt::ItemFlags flags = item->flags();
    flags ^= Qt::ItemIsUserCheckable;
    item->setFlags(flags);
    In the second code you are removing that line and assuming that it will not display.

    What's the point you want to say?

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    7

    Re: Can not remove Checkbox of QListWidgetItem

    i want to make the checkbox disappear, so i tried to remove the checkbox with the seconde code.

    And i traced the paint(), the return valule of data(Qt::CheckStateRole) is used to decide whether the checkbox should be drawn.

    Do you have any method to make the checkbox disappear?

  4. #4
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: Can not remove Checkbox of QListWidgetItem

    You are removing checkbox.
    Also you can check this,

    You may hide checkbox using this hideitem.
    http://doc.qt.nokia.com/4.6/model-vi...l#hidden-items

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    7

    Re: Can not remove Checkbox of QListWidgetItem

    Thanks! I checked the hideitem. the functionality can hide entire item, while can not only hide the checkbox of the item.

    BTW, void QListWidget::setItemHidden ( const QListWidgetItem * item, bool hide ) is an obsolete member for QListWidget in Qt4.6.

Similar Threads

  1. Replies: 2
    Last Post: 2010-07-31, 17:19
  2. QWidget in QListWidgetItem off-center
    By danhicksbyron in forum Qt
    Replies: 4
    Last Post: 2010-03-18, 16:24
  3. Customize QListWidgetItem, how to?
    By stegemann in forum Qt
    Replies: 3
    Last Post: 2010-02-05, 02:10
  4. Checkbox?
    By mrmop in forum Mobile Java General
    Replies: 4
    Last Post: 2003-12-19, 13:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×