Reputation: 4333
I search almost everywhere how to add verticalScrollBar to QListWidget
, however I couldn't find suitable answer for my question.
I am trying to show output of QProcess
to QListWidget
. However there is no vertical scroll bar. In my example I have 200 line, but I can only see 5 line, because of there is no scroll bar. Here is what I tried;
QString program = "ssh";
QStringList arguments;
arguments << "localhost" << "tail" << "-n" << "200" << "log.txt";
QProcess *myProcess = new QProcess(this);
myProcess->start(program, arguments);
myProcess->waitForFinished();
QString output(myProcess->readAllStandardOutput());
QListWidgetItem *newItem = new QListWidgetItem;
newItem->setText(output);
ui->listWidget->insertItem(0, newItem);
ui->listWidget->setMinimumWidth(ui->listWidget->sizeHintForColumn(0));
ui->listWidget->verticalScrollBar()->width()`;`
Upvotes: 0
Views: 2135
Reputation: 1878
The Items in a QListWidget
do not usually word-wrap, so you probably enabled word wrap using setWordWrap(true)
.
Also, you can force a scrollbar to be visible using setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn)
.
Finally use setVerticalScrollMode(QAbstractItemView::ScrollPerPixel)
so you can scroll through single large items. The default is ScrollPerItem
, which is why you don't see any scrollbar: There is no need for one because the item is already in the viewport.
Upvotes: 1