QTableWidgetItem 缩小
我在使用 QTableWidgetItem 时遇到问题。 我通常像这样使用 QTableWidget
this->setItem(i, j, new QTableWidgetItem());
this->item(i, j)->setText(string);
我正在写入的列很窄,只有大约 20px。我需要在其中写入 2 位数字,根据定义我无法调整列的大小。
问题是,一旦文本与列宽重叠,它就会完全消失,只出现三个点(甚至什么也没有)。 我可以抑制这种行为吗?我不介意是否会有 1-2 像素的重叠/剪辑,但我绝对对文本消失感到不舒服。
感谢您的任何帮助。
编辑:
好吧,经过几次尝试,我必须说TextElide想法有效,但是,现在我面临另一个问题。有时,当 QTableWiddgetItem 中有更多行时,底部的行就会消失,只有顶部的行可见。有什么建议为什么会发生这种情况吗?
编辑2:
它看起来像这样......请注意,图像之间的唯一区别是更大的字体大小。单元格的高度绝对足以包含所有文本。 http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug1 .png http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug2.png
I have an issue usign QTableWidgetItem.
I normally use the QTableWidget like this
this->setItem(i, j, new QTableWidgetItem());
this->item(i, j)->setText(string);
The column I'm writing to is narrow, only about 20px. I need to write 2 digits in there and from the definition I cannot resize the column.
The problem is that once the text overlaps the column width, it totally disappears and only three dots (or even nothing) appear instead.
Can I suppress this behavior? I dont mind if there will be 1-2px overlap/clip, but I'm definitely not comfortable with the text disappearance.
Thanks for any help.
EDIT:
Well, after a couple of tries, I must say that the TextElide think works, however, now I face another problem. Sometimes, when there are more lines in the QTableWiddgetItem, the bottom lines just disappear and only the top one is visible. Any suggestions why this may happen?
EDIT 2:
It looks like this....note that the only difference between the images is a bigger font size. The cells are definitely high enough to containt all the text.
http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug1.png
http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug2.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅 textElideMode 属性。
this->setTextElideMode(Qt::ElideNone)
将删除点。See the textElideMode property.
this->setTextElideMode(Qt::ElideNone)
will remove the dots.您是否尝试过设置项目的 sizeHint ?
请参阅此
Have you tried setting the sizeHint of the item?
See this