Home > Blockchain >  QTableWidgetItem displays three dots instead of full text
QTableWidgetItem displays three dots instead of full text

Time:07-05

I'm using a QTableWidget with four column witch i programaticaly fill with QTableWidgetItem in a loop. it's working but the full text is not displaying, it show three dots instead like there isn't enough space: QTableWidgetItem show 3 dots

if i double click on a row it will display the whole text:

QTableWidgetItem display full text on edit

How to set QTableWidgetItem programatically to fill all available space, or disable the 3 dots system and just display the whole text event if it will overflow ?

Here my simplified code that just fill the second problematic column:

    vector<OperationLine> lines = db->getOperationLines(ui->dateEditFrom->date(),ui->dateEditTo->date());

    ui->operationTableWidget->setRowCount(lines.size());
    ui->operationTableWidget->setTextElideMode(Qt::ElideNone);

    for(int i=0;i<lines.size();i  ){

        QTableWidgetItem* libelle_item = new QTableWidgetItem(lines.at(i).libelle);
        libelle_item->setToolTip(lines.at(i).libelle);
        setDocumentMode(libelle_item);
        libelle_item->setSizeHint(QSize(500,50));// <-does not seem to work
        ui->operationTableWidget->setItem(i,1,libelle_item);
    }

    ui->operationTableWidget->resizeColumnsToContents();

ps: OperationLine is a simple class and .libelle is just a QString. Manualy resizing the column does not help. I also tried to disable editing and it does not help either. However if i comment my loop and manualy add item with QtCreator it seem to work as expected.

CodePudding user response:

My original string contain return lines, removing them like:

QString s = lines.at(i).libelle;
s.replace('\n',' ');
ui->operationTableWidget->setItem(i,1,s);

is working.

As @Scheff'sCat pointed out in the comment of my original post, using the accepted solution at How to prevent too aggressive text elide in QTableview? work too and will display multiple lines withouts the dots in the wrong place.

  • Related