Results 1 to 5 of 5

Thread: I have added checkboxes in QtreeWidget ,How can i add functions to that checkboxes ?

  1. #1
    Join Date
    Jun 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default 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
    Capture---.PNG

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: I have added checkboxes in QtreeWidget ,How can i add functions to that checkbox

    By connecting signals to slots. Read the docs.

  3. #3
    Join Date
    Jun 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default 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:n_pushButton_Openfile_clicked()
    {
    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)
    {

    }

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: I have added checkboxes in QtreeWidget ,How can i add functions to that checkbox

    When do you want to perform these actions;
    1. immediately after the check state changes on each item, or
    2. 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.

  5. #5
    Join Date
    Jun 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default 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 .....

Similar Threads

  1. QTreeView and CheckBoxes
    By FreeG in forum Qt Programming
    Replies: 2
    Last Post: 9th December 2009, 10:36
  2. checkboxes in a tableview,
    By mimmo_kallon in forum Newbie
    Replies: 3
    Last Post: 13th March 2008, 20:01
  3. checkboxes
    By abrou in forum Newbie
    Replies: 2
    Last Post: 1st February 2008, 19:52
  4. Checkboxes in QAbstractITemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th November 2007, 21:23
  5. how i can add checkboxes to contextMenus?
    By quickNitin in forum Newbie
    Replies: 3
    Last Post: 15th November 2006, 13:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.