qtableWidgetItem显示三个点,而不是全文

发布于 2025-02-12 06:30:12 字数 1361 浏览 0 评论 0原文

我使用的是带有四列女巫的QtableWidget,我在循环中使用QTableWidgetItem填充了QtableWidget。它正在工作,但全文没有显示,它显示了三个点,就像没有足够的空间一样:

如果我双击一行,它将显示整个文本:

如何以编程为qtableWidgetItem 所有可用空间,或禁用3个点系统,只需显示整个文本事件吗

填写

    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();

?只是QString。手动调整列的大小无济于事。我还试图禁用编辑,这也无济于事。但是,如果我用QTCreator评论我的循环和手动添加项目,它似乎可以按预期工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2025-02-19 06:30:14

我的原始字符串包含返回线,将其删除,例如:

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

正在工作。

正如 @scheff'scat在我的原始帖子的评论中指出的那样,使用接受的解决方案如何防止在qtableview中防止过于激进的文本? 也可以工作,并且将显示多行,而不会在错误的位置上点数。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文