Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [Solved]QTableWidget remove row spaces
Forum Updated to NodeBB v4.3 + New Features

[Solved]QTableWidget remove row spaces

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 1 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tecnova
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tecnova
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tecnova
        wrote on last edited by
        #3

        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/

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved