mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
desktop: avoid crashes on drag&drop in GroupedLineEdit
If the user manages to "scroll" through the QPlainTextEdit by a drag&drop action, the state of the widget becomes inconsistent. On the one hand, the text-block says that it has one line. On the other hand, its layout says that it has no line. When trying to fetch the line, a crash occurs. Try to detect such a strange state and return early in GroupedLineEdit::paintEvent(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0278f3f90c
commit
a9a4249b23
1 changed files with 9 additions and 1 deletions
|
@ -161,7 +161,15 @@ void GroupedLineEdit::keyPressEvent(QKeyEvent *e)
|
|||
|
||||
void GroupedLineEdit::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QTextLine line = document()->findBlock(0).layout()->lineAt(0);
|
||||
// Do some sanity checks. Without these, the code may crash if
|
||||
// the user manages to scroll the text box by drag&drop actions.
|
||||
const QTextBlock &block = document()->findBlock(0);
|
||||
if (block.lineCount() <= 0)
|
||||
return QPlainTextEdit::paintEvent(e);
|
||||
const QTextLayout *layout = block.layout();
|
||||
if (layout->lineCount() <= 0)
|
||||
return QPlainTextEdit::paintEvent(e);
|
||||
QTextLine line = layout->lineAt(0);
|
||||
QPainter painter(viewport());
|
||||
|
||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||
|
|
Loading…
Reference in a new issue