Qt Text Selection White Line and Text Width

你。 提交于 2021-02-07 20:27:36

问题


I want to customize the text Selection in QTextEdit, I want two things:

  1. Remove white spaces/lines when selecting.
  2. Be able to choose the width of the selection, either the widget width or the text width.

White Spaces/Lines :

Typically, what I would like is that : (from Bear app) :

Bear Text Selection

While using QTextEdit widget, I've noticed that when I select the text, there are white lines between selected lines :

White Lines Issue

To fix this, I tried some things:

I have set some colors to the current QTextBlockFormat and the QTextCharFormat to see the precise dimension of each. It seems that the problem comes from the QTextBlockFormat but I don’t know how to fix it. (yellow = QTextCharFormat, red = QTextBlockFormat)

Text Selection With colors

I’ve tried to change the lineHeight with QTextBlockFormat::setLineHeight(…); But when I do so, the selection doesn't select the blank spaces :

Line Height

Selection Width :

The second problem is that when selecting the text the full line is selected (See image 1). I would like to select only the text, like in Photoshop :

Photoshop Selection

I tried with stylesheet : show-decoration-selected but it seems to only work with QListView.

来源:https://stackoverflow.com/questions/50823636/qt-text-selection-white-line-and-text-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!