QAbstractScrollArea::setHorizontalBarPolicy updates the listWidget in bad Way
-
listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
Currently my code is like this and and I Have a splitter, but if I move the split to the point that I don't need more the scroll, the list is updated in the sense that if I were at the line 450, the list goes up to the line 1. How avoid such behavior?
-
The widget below does not display the behaviour you describe.
#include "widget.h" #include <QListWidget> #include <QSplitter> #include <QTextEdit> #include <QVBoxLayout> Widget::Widget(QWidget *parent) : QWidget(parent) { QListWidget *list = new QListWidget(this); list->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); // ^^^ this is the default in many styles anyway QString entry; for (int row = 0; row < 10; ++row) { entry.append("word "); list->addItem(QString("Row %1 %2").arg(row).arg(entry)); } QTextEdit *edit = new QTextEdit(this); QSplitter *splitter = new QSplitter(this); splitter->addWidget(list); splitter->addWidget(edit); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(splitter); } Widget::~Widget() { }
Before
After stretching horizontally
Row 2 stays where it was after the horizontal scroll bar disappears.
[Edit: wrong screen shots in original post] -
The widget below does not display the behaviour you describe.
#include "widget.h" #include <QListWidget> #include <QSplitter> #include <QTextEdit> #include <QVBoxLayout> Widget::Widget(QWidget *parent) : QWidget(parent) { QListWidget *list = new QListWidget(this); list->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); // ^^^ this is the default in many styles anyway QString entry; for (int row = 0; row < 10; ++row) { entry.append("word "); list->addItem(QString("Row %1 %2").arg(row).arg(entry)); } QTextEdit *edit = new QTextEdit(this); QSplitter *splitter = new QSplitter(this); splitter->addWidget(list); splitter->addWidget(edit); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(splitter); } Widget::~Widget() { }
Before
After stretching horizontally
Row 2 stays where it was after the horizontal scroll bar disappears.
[Edit: wrong screen shots in original post]@ChrisW67 You are right, I was setting an ItemUpdate after the Splitter resize through setResizeMode(QListWidget::Adjust), it was causing my bad behavior, after removing no problem was encountered