简体   繁体   English

QTableWidgetItem 显示三个点而不是全文

[英]QTableWidgetItem displays three dots instead of full text

I'm using a QTableWidget with four column witch i programaticaly fill with QTableWidgetItem in a loop.我正在使用带有四列的 QTableWidget,我在循环中以编程方式填充 QTableWidgetItem。 it's working but the full text is not displaying, it show three dots instead like there isn't enough space:它正在工作,但未显示全文,而是显示三个点,就像没有足够的空间一样: QTableWidgetItem 显示 3 个点

if i double click on a row it will display the whole text:如果我双击一行,它将显示整个文本:

QTableWidgetItem 在编辑时显示全文

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?如何以编程方式设置 QTableWidgetItem 以填充所有可用空间,或禁用 3 点系统并在溢出时仅显示整个文本事件?

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. ps:OperationLine是一个简单的class,.libelle只是一个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.但是,如果我评论我的循环并使用 QtCreator 手动添加项目,它似乎可以按预期工作。

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?正如@Scheff'sCat 在我原始帖子的评论中指出的那样,使用如何在 QTableview 中防止过于激进的文本省略中接受的解决方案? work too and will display multiple lines withouts the dots in the wrong place.也可以工作,并且会在错误的位置显示多行而没有点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM