Archived:QListWidget with checkbox
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
This code example shows the procedure of adding checkbox to a QListWidget. Multiple items can be checked in a list widget by clicking at any place on item.
Article Metadata
Code Example
Source file: Media:Mobisnippet.zip
Tested with
Devices(s): Symbian emulator,E7
Compatibility
Platform(s): Symbian
Article
Keywords: QGridLayout, QListWidget
Created: mind_freak
(10 Oct 2011)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Function and Functionality
This function helps to set the checkbox on list widget, items in list are checkable and multiple selection is possible.
setFlags(widget->item(i)->flags() |Qt::ItemIsUserCheckable);
Sets the check state of the list item to
setCheckState(Qt::Unchecked);
Code Snippet
.h file
#ifndef
MOBIWIDGET_H
#define MOBIWIDGET_H
#include <QWidget>
#include<QListWidgetItem>
namespace Ui {
class mobiwidget;
}
class mobiwidget : public QWidget
{
Q_OBJECT
public:
explicit mobiwidget(QWidget *parent = 0);
~mobiwidget();
private slots:
void on_pushButton_clicked();
private:
Ui::mobiwidget *ui;
public slots:
void myfun();
void myfunction(QListWidgetItem*);
};
#include"mobiwidget.h"
#include "ui_mobiwidget.h"
mobiwidget::mobiwidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::mobiwidget)
{
ui->setupUi(this);
QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(myfun()));
QObject::connect(ui->listWidget,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(myfunction(QListWidgetItem*)));
}
mobiwidget::~mobiwidget()
{
delete ui;
}
void mobiwidget::on_pushButton_clicked()
{
ui->listWidget->addItem(ui->lineEdit->text());
}
void mobiwidget::myfun()
{
for(int i=0;i<ui->listWidget->count();i++){
ui->listWidget->item(i)->setFlags(ui->listWidget->item(i)->flags() |Qt::ItemIsUserCheckable);
ui->listWidget->item(i)->setCheckState(Qt::Unchecked);
}
}
void mobiwidget::myfunction(QListWidgetItem *item){
if(item->checkState())
item->setCheckState(Qt::Unchecked);
else
item->setCheckState(Qt::Checked);
}
Snapshot
Source Code
Download here File:Mobisnippet.zip


(no comments yet)