Skip to content

Commit

Permalink
MultiLineEditDelegate: center one-line text vertically in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jul 28, 2023
1 parent 857b7cb commit f28ea7b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/library/multilineeditdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ void MultiLineEditDelegate::adjustEditor(MultiLineEditor* pEditor,
// Note: also setBackgroundVisible(true) on the editor to paint the entire
// rectangle, not just the document.
int txtH = fm.lineSpacing() * lines;
// If it's just one line center the text vertically like QLineEdist do.
// Note that the offset is applied in all directions which, hence with very
// tall library row spacing the left offset may be disturbing.
int diffH = (iRect.height() - txtH - pEditor->frameWidth() * 2) / 2;
if (lines == 1 && diffH > 1) {
pEditor->document()->setDocumentMargin(diffH);
} else { // Reset if lines were added
pEditor->document()->setDocumentMargin(0);
}

int newH = std::max(txtH, iRect.height());
// Limit editor to visible table height
QRect tableRect = m_pTableView->viewport()->rect();
Expand Down

0 comments on commit f28ea7b

Please sign in to comment.