Skip to content

Commit

Permalink
MultiLineEditDelegate: always remove scrollbars for one-liners
Browse files Browse the repository at this point in the history
setting seems to be reset if document size changed while line count didn't
  • Loading branch information
ronso0 committed Jul 25, 2023
1 parent 2c35218 commit 1d25ece
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/library/multilineeditdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ QWidget* MultiLineEditDelegate::createEditor(QWidget* pParent,
void MultiLineEditDelegate::adjustEditor(MultiLineEditor* pEditor, const QSizeF size) const {
// Compared to QTextEdit, size.height() is the line count (Qt speak: blocks)
int newLineCount = static_cast<int>(round(size.height()));
// Only act if line count changed
// Remove the scrollbars if content is just one line to emulate QLineEdit
// appearace, else enable auto mode.
Qt::ScrollBarPolicy pol(newLineCount > 1 ? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff);
pEditor->setVerticalScrollBarPolicy(pol);
pEditor->setHorizontalScrollBarPolicy(pol);

// Only resize if line count changed
if (newLineCount == m_lineCount) {
return;
} else {
m_lineCount = newLineCount;
}

// Remove the scrollbars if content is just one line to emulate QLineEdit
// appearace, else enable auto mode.
Qt::ScrollBarPolicy pol(m_lineCount > 1 ? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff);
pEditor->setVerticalScrollBarPolicy(pol);
pEditor->setHorizontalScrollBarPolicy(pol);

// Calculate the content height
int lines = m_lineCount;
// Add extra margin so the horizontal scrollbar doesn't obstruct the last
Expand Down

0 comments on commit 1d25ece

Please sign in to comment.