Qt - invalid use of incomplete type 'class QScrollBar' - Add horizontal scroll bar to text edit widget

StackOverflow https://stackoverflow.com/questions/19300217

Pregunta

The default QPlainTextEdit has only vertical scroll bar, I want to add horizontal scroll bar.

I tried this (this code in the constructor of the QMainWindow class)

QPlainTextEdit * editor = new QPlainTextEdit(this);
QScrollBar * hScroll = new QScrollBar(Qt::Horizontal);
editor->addScrollBarWidget(hScroll);
setCentralWidget(editor);

but the build failed with the error (invalid use of incomplete type 'class QScrollBar').

¿Fue útil?

Solución

You can easily add horizontal scroll bar in the QPlainTextEdit Widget by setting the line wrap property, your code should be:

QPlainTextEdit * editor = new QPlainTextEdit(this);
editor->setLineWrapMode(QPlainTextEdit::NoWrap);
setCentralWidget(editor);

QPlainTextEdit::NoWrap mode will automatically add the horizontal scroll bar when the line width exceed the editor width.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top