简体   繁体   English

QT C ++ QTableWidget(Item)部分斜体化(强调)文本

[英]QT C++ QTableWidget(Item) partially italicize (emphasize) text

Problem 问题

I'm using QTableWidget (Item) for presentation of some data. 我正在使用QTableWidget (项目)来表示某些数据。 For that i need to italicize or set bold some parts of text. 为此,我需要将文本的某些部分用斜体或粗体显示。 Problem: I don't want to italicize the whole cell/box, just parts of text in a cell. 问题:我不想将整个单元格/框斜体化,而只是将单元格中的部分文本斜体化。

Ideas 主意

: Using the QTableWidgetItem refering to the correspondent cell and trying to modify the style (eg setFont(font)). :使用QTableWidgetItem引用对应的单元格并尝试修改样式(例如setFont(font))。 But this operations always seem to alter the whole cell? 但是这种操作似乎总是会改变整个细胞吗?

I also found this which doesn't help me for my QTableWidget problem. 我还发现对我的QTableWidget问题没有帮助。

Wanted 通缉

: To Have a QTableWidget with eg 2 rows and collumns containing cells like: :要有一个QTableWidget,例如包含2行和包含单元格的列,例如:

Exa mple Cell Text 示例单元格文本

(Nice Notation like Exa<b>mple</b> Cell <i>Text</i> is only a secondary aspect) (像Exa<b>mple</b> Cell <i>Text</i>这样的漂亮符号只是次要的方面)

Note: Example should be one word. 注意:示例应为一个单词。

Solved 解决了

I didn't see the wood for the trees. 我没有看到树木的木头。 Thanks to Salvatore Avanzo, he is totally right. 感谢Salvatore Avanzo,他完全正确。

All Item Widget classes provide functionality to render/paint something custom in each cell. 所有Item Widget类都提供了在每个单元格中呈现/绘制自定义内容的功能

QTableWidget provides setCellWidget(.. QWidget..) ; QTableWidget提供setCellWidget(.. QWidget..) ; QListWidget and QTreeWidget provide setItemWidget(..QWidget..) . QListWidgetQTreeWidget提供setItemWidget(..QWidget..) Therefore you can use any Subclass of QWidget (base of all ui objects) to paint something custom. 因此,您可以使用QWidget的任何子类(所有ui对象的基础)来绘制一些自定义内容。 For my aim i needed the capability to set a custom partially emphasized/italicized text. 为了我的目标,我需要能够设置自定义的部分强调/斜体文本。 The Refering Subclass of QWidget for painting texts is QLabel (It itself is also a subclass of QPainDevice). 用于绘制文本的QWidget的Refering子类是QLabel (它本身也是QPainDevice的子类)。 A QWidget/Subclass of QWidget is drawed when paintEvent(..) is invoked (QLabel reimplemented that). 调用paintEvent(..)时将绘制QWidget的QWidget / QWidget子类(重新实现QLabel)。 QLabel also supports RichText functionality (flag is used by default), eg you can use <b>foo</b> to get foo . QLabel还支持RichText功能(默认情况下使用flag),例如,您可以使用<b>foo</b>获取foo

So that's perfectly fits my problem and i will now use this solution. 因此,这完全适合我的问题,我现在将使用此解决方案。

Forecast for better structured solution 预测更好的结构化解决方案

The unattractive aspect of the above mentioned solution is, that design and data get totally mixed. 上述解决方案的吸引人之处在于,设计和数据完全混合在一起。 Editing Text in a QLabel is possible if you set the refering Interaction tags. 如果设置了引用的交互标签,则可以在QLabel中编辑文本。 But then you always need to use QLabel to get the text. 但是,您始终需要使用QLabel来获取文本。 When additionally setting an QTableWidgetItem in the Cell which also uses QLabel, they overlay ugly. 在还使用QLabel的单元格中另外设置QTableWidgetItem时,它们很难覆盖。 So one could use QTableView. 因此,可以使用QTableView。 Here is a link . 这是一个链接

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

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