1 Attachment(s)
I have added checkboxes in QtreeWidget ,How can i add functions to that checkboxes ?
Hello
I have added checkboxes in QtreeQidget , I can check or uncheck them . But How can i add functions to that checkboxes ?
for example if i click one check box then a certain function is performed.
I have attached Image file
Your suugestions would be highly appreciated ...
thanks
Attachment 11236
Re: I have added checkboxes in QtreeWidget ,How can i add functions to that checkbox
By connecting signals to slots. Read the docs.
Re: I have added checkboxes in QtreeWidget ,How can i add functions to that checkbox
I have seen Signals and slots but could not figure it out how to use them in this case.
Here is txt file which i want to open and load it in qtreewidget
1200,Shahbaz,Ifc,laja
2001,ali,Step,kdh
1992,ikaka,psp,ayaj
Here is my code
QT_ApplicationWindow::QT_ApplicationWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::QT_ApplicationWindow)
{
ui->setupUi(this);
ui->label_OrigName->setText("File Name :");
ui->label_FilePath->setText("File Path :");
//set the number of columns
ui->treeWidget->setColumnCount(5);
addRoot ("ID","Type","Name","UID","Check");
//set the headers
// ui->treeWidget->setHeaderLabels(QStringList()<<"ID"<<"Type"<<"Nam e"<<"GUID");
}
QT_ApplicationWindow::~QT_ApplicationWindow()
{
delete ui;
}
void QT_ApplicationWindow::on_pushButton_Openfile_click ed()
{
QString fileName = QFileDialog::getOpenFileName(
this, tr ("Open File"), "C:\\",
"All files (*.*);; Text File (*.txt);; IFC File (*.ifc);; STEP File (*.step);;XML files (*.xml);;Image files (*.jpg *.png)");
if (!fileName.isEmpty())
ui->label_FileName->setText(QFileInfo(fileName).fileName());
QDir dir = QFileInfo(fileName).absoluteDir();
ui->lineEdit_FileDir->setText(dir.absolutePath());
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice ::Text))
QMessageBox::critical(this,tr("STOP"),tr("Error with loading"));
QTextStream in(&file);
QString line;
// ui->textBrowser->setText(in.readAll());
do
{
line = in.readLine();
if(line.isEmpty())
continue;
QTreeWidgetItem *item = new QTreeWidgetItem (ui->treeWidget);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEditable);
QList <QString> parts = line.split(",", QString::KeepEmptyParts);
QString L;
QListIterator<QString> Iter (parts);
while (Iter.hasNext())
{
for (int i=0 ; i<4; i++)
{
L = Iter.next();
item->setText(i,L);
item->setCheckState(4,Qt::Unchecked);
}
}
} while (!in.atEnd());
}
void QT_ApplicationWindow :: addRoot(QString ID, QString Type, QString Name, QString UID, QString A)
{
}
Re: I have added checkboxes in QtreeWidget ,How can i add functions to that checkbox
When do you want to perform these actions;
- immediately after the check state changes on each item, or
- for all checked items when an "OK" button is clicked?
1. Connect to the dataChanged() signal from the tree widget's model()
2. In your button slot, iterate over the column of the tree checking the check state and acting on those that are checked/unchecked.
Re: I have added checkboxes in QtreeWidget ,How can i add functions to that checkbox
I want to know
when i check the particular checkbox , message box appears .....