[Solved]QTableWidget remove row spaces



  • Hi,
    I have just started programming with QTCreator (about 3 weeks now).
    At the moment I'm working on a QTableWidget.
    I read Data from a csv file which also contains long text for one cell.

    Because @tableWidget->resizeColumnsToContents()@ makes the column to big, I add newlines every 50 character with:
    @
    while(!in.atEnd())
    {
    ui->tableWidgetDictionary->insertRow(row);
    datalist = in.readLine().split(',');
    for(int i = 0; i < ui->tableWidgetDictionary->columnCount(); i++)
    {
    tmp = datalist.at(i);
    // this for adds newline to the string if he is bigger than 50 characters
    for(int j = 50; j < tmp.size(); j += 50)
    {
    int count = j;
    //search for the next space
    while((QString(tmp.at(count)) != " ") && (count < tmp.size()-1))
    {
    count++;
    }
    if(count < tmp.size()-1)
    tmp.insert(count,"\n");
    }
    ui->tableWidgetDictionary->setItem(row,i,new QTableWidgetItem(tmp));
    ui->tableWidgetDictionary->item(row,i)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
    }
    row++;
    }
    ui->tableWidgetDictionary->setWordWrap(true);
    ui->tableWidgetDictionary->resizeRowsToContents();
    ui->tableWidgetDictionary->resizeColumnsToContents();
    @

    when I do this I get the Rows like this:

    Text
    Text


    how can I make that the rows look more tighter to their content like:

    Text
    Text

    Thanks for your help



  • Ok this:
    @QObject::connect(
    ui->tableWidgetDictionary->horizontalHeader(), SIGNAL(sectionResized(int,int,int)),
    ui->tableWidgetDictionary,
    SLOT(resizeRowsToContents()));@

    makes it tighter when I resize the column manually. But my table has about 40k rows and the main window freezes for a while.

    So how can I make the rows fit tighter to its content when I insert them?



  • I soved it, by replacing the widget with a view.
    see here:
    "How to limit rows for QTableView":http://qt-project.org/forums/viewthread/33415/


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.