Results 1 to 3 of 3

Thread: Iterate and get Checked QTable items??

  1. #1
    Join Date
    Mar 2006
    Posts
    47
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Iterate and get Checked QTable items??

    Hi,

    I am working on QTable and QTableItem. I have a table containing three columns(Name, Extension, Size) . I am inserting checkable item in col first and Extension is readonly and Size col is editable. I am using QT 3.3.5. I am using the following code for the table item insertion:-

    int j=0;
    int k=0;
    table1->setItem( j, 0, new QCheckTableItem( table1, Name ) );
    table1->setItem( k, 1, new QTableItem( table1, QTableItem::Never,ExtensionName ) );
    j++;
    k++;

    Now My problem is that
    1) I want to iterate through the each columns items.
    2) I want to get no. of Checked items in first col and item also.
    3) Third column is editable but when i double click on this column then only the cursor for editing appears, how i can do this on single click and give focus to edit.
    4) When i inserting using the above code then last row is inserted which only have checkbox.

    Best Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Iterate and get Checked QTable items??

    Quote Originally Posted by darpan
    1) I want to iterate through the each columns items.
    Qt Code:
    1. for(int i=0;i<table->numRows();i++){
    2. QTableItem *item = table->item(i, 0);
    3. qDebug("Column 0 of item %d says '%s'", i, item->text().latin1());
    4. }
    To copy to clipboard, switch view to plain text mode 

    2) I want to get no. of Checked items in first col and item also.
    Qt Code:
    1. uint itemschecked = 0;
    2. for(int i=0;i<table->numRows();i++){
    3. QTableItem *item = table->item(i, 0);
    4. QCheckTableItem *checkitem = dynamic_cast<QCheckTableItem*>(item);
    5. if(checkitem && checkitem->isChecked()) itemschecked++;
    6. }
    7. qDebug("Total of %d items checked", itemschecked);
    To copy to clipboard, switch view to plain text mode 

    3) Third column is editable but when i double click on this column then only the cursor for editing appears, how i can do this on single click and give focus to edit.
    Qt Code:
    1. connect(table, SIGNAL(clicked(int, int, int, const QPoint &), table, SLOT(editCell(int, int)));
    To copy to clipboard, switch view to plain text mode 

    4) When i inserting using the above code then last row is inserted which only have checkbox.
    I don't understand your question, sorry

  3. #3
    Join Date
    Jan 2006
    Location
    Skopje, Macedonia
    Posts
    11
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Iterate and get Checked QTable items??

    Hi,

    1.

    iteration is very simple
    Qt Code:
    1. for (i=0; i< table->numRows(); i++)
    2. for(j=0; j < table->numCols(); j++)
    3. {
    4. // do something with the table
    5. }
    To copy to clipboard, switch view to plain text mode 
    the above code goes through every cell of the table

    2.
    if ((QComboBox*)table->cellWidget( i, j))->isChecked() cnt++;


    cnt = counter of checked items
    i, j = row and column of the cell


    3.

    in the clicked signal handler
    void QTable::clicked ( int row, int col, int button, const QPoint & mousePos ) [signal]

    set cell editing to by using the editCell() function

    http://doc.trolltech.com/3.3/qtable.html#editCell

    or connect the the clicked signal to cellEdit slot


    4.

    check the setCellWidget() function

    http://doc.trolltech.com/3.3/qtable.html#setCellWidget



    chombium

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.