Results 1 to 2 of 2

Thread: QTableWidget's rows deletion and again insertion

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

    Default QTableWidget's rows deletion and again insertion

    Hi,
    (1) When i am inserting items in QTableWidget then rowcount is also appearing with each row. I don't want to show rowcount with each row. How i can hide this rowcount.
    (2) I am using following code to delete items from the QTableWidget and then i have to again insert items in QTableWidget but when after deleting items i am inserting items then the column header are also disappear and column count like 1,2,3 appears in place of header. I am using QT4.1 on mac.

    How i can keep unchanged QTableWidget's header after deleting rows in it.

    I am using the following code to delete and then again insert items in QTableWidget:-

    if(EditHeaderDlgObj->exec()==QDialog::Accepted)
    {
    tableWidget->clear();
    while(tableWidget->rowCount())
    {
    int row=tableWidget->rowCount();
    tableWidget->setRowCount(row-1); // delete one row at a time

    }

    HEADER_FILE *tmp = SearchHeaderStart;
    int RowCount = 0,
    row = 0;

    QTableWidgetItem *item=NULL;

    QString FileSize;
    while(tmp)
    {
    row = tableWidget->rowCount(); // current row count
    tableWidget->setRowCount(row+1); // add one row

    item=new QTableWidgetItem(tmp->bSoftwareName);

    tableWidget->setItem( RowCount, 0, item );

    item=new QTableWidgetItem(tmp->bFileExt);
    tableWidget->setItem( RowCount, 1, item );


    FileSize= FileSize.setNum(tmp->dwFileSize/1024);
    item=new QTableWidgetItem(FileSize);
    tableWidget->setItem( RowCount, 2, item );



    RowCount++;

    tmp = tmp->next;
    }//end of while
    RemoveButton->setEnabled(FALSE);
    EditButton->setEnabled(FALSE);
    qApp->processEvents();
    }



    Thanks and Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidget's rows deletion and again insertion

    Quote Originally Posted by darpan View Post
    (1) When i am inserting items in QTableWidget then rowcount is also appearing with each row. I don't want to show rowcount with each row. How i can hide this rowcount.
    Are you talking about the vertical header? If so, try QTableView::verticalHeader() and QWidget::hide().
    Qt Code:
    1. tableWidget->verticalHeader()->hide();
    To copy to clipboard, switch view to plain text mode 

    By the way,
    Quote Originally Posted by darpan View Post
    Qt Code:
    1. tableWidget->clear();
    2. while(tableWidget->rowCount())
    3. {
    4. int row=tableWidget->rowCount();
    5. tableWidget->setRowCount(row-1); // delete one row at a time
    6. }
    To copy to clipboard, switch view to plain text mode 
    is equivalent of
    Qt Code:
    1. tableWidget->clear();
    2. tableWidget->setRowCount(0);
    To copy to clipboard, switch view to plain text mode 
    with much less hassle. Removing rows one by one causes several repaints (which Qt might actually merge for you, but still...)

    I somehow have a feeling that a QTreeWidget with multiple columns and root decoration disabled would be more appropriate for you. But anyway, could you please use [ code ]-tags around your code postings to make them more readable.
    J-P Nurmi

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
  •  
Qt is a trademark of The Qt Company.