问题
I want to customize the text Selection in QTextEdit, I want two things:
- Remove white spaces/lines when selecting.
- 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