Unsolved QTableWidgetItem while editing has smaller font
-
When I double-click on a QTableWidgetItem in order to edit its text, the font that it uses is smaller than the font that is used after editing has ended.
I'm using a QPlainTextEdit subclass for the editor. There is only one place where the "delegate" that creates the QPlainTextEdit editors is defined, so it is the same delegate for ALL cells.
Why was it designed this way? If I need to create QPlainTextEdits that have different characteristics for different cells, it would require some crazy coding practices, like letting the delegate have access to my actual data (not the table model).
Furthermore the delegate only knows about the "index", not the row/column. It's not clear how convert the index to a row/column.
-
@Publicnamer said in QTableWidgetItem while editing has smaller font:
Furthermore the delegate only knows about the "index", not the row/column. It's not clear how convert the index to a row/column.
Not an answer to your original question. But be aware the
QModelIndex
has membersrow()
&column()
for that, so you do know these wherever you have an index. -
@JonB OK thanks.
Setting the font for all QPlainTextEdit, I can achieve somewhat OK results.
However the real problem with QPlainTextEdit is that it has internal padding such that if the original row needed to be 60 pixels high to accommodate the text, the QPlainTextEdit's row will need to be 65 or 70 pixels high.
Is there a way to eliminate the internal padding of a QPlainTextEdit?
-
@Publicnamer
You can set the document margin with:
setDocumentMargin(qreal margin)
(the default value is 4 i think) -
@mpergand What class has that method? I don't see it anywhere, not QPlainTextEdit, QTableWidget, nor QTableWidgetItem.
-
@Publicnamer
QTextDocument::setDocumentMargin().QTextDocument *QPlainTextEdit::document() const lets you access the
QTextDocument
it is using. -
@JonB Yep I found it. I'm now doing setDocumentMargin(0), which helps a little but there is still a margin of maybe 2 pixels at the top and bottom. Double clicking on a row results in the text shifting down a couple pixels and the vertical scrollbar appearing.