Reputation: 4720
I want to have a list view just like the one in Windows' file explorer: The data is shown into columns. So I set up a QListView
with the code below.
It looks totally the same (see picture).
But one major drawback: When resizing the window, the wrapping is very slow. On the contrary, the Window's file browser is very fast.
How can I speed up the wrapping in the QListView?
h:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void resizeEvent(QResizeEvent *);
private:
Ui::MainWindow *ui;
};
cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QStandardItemModel* m=new QStandardItemModel;
for (int i=100;i<1000;++i){
m->insertRow(i-100,new QStandardItem(QString::number(i).repeated(5)+" "));
}
ui->listView->setModel(m);
ui->listView->setWrapping(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::resizeEvent(QResizeEvent *e)
{
QMainWindow::resizeEvent(e);
ui->listView->setWrapping(ui->listView->isWrapping());
}
Upvotes: 1
Views: 691
Reputation: 42
You don't need to set wrapping every time the widget is resized. Qt is looking for the isWrapping
property when resized and decides if a new segment is needed. You just need to set the flow
property LeftToRight
or TopToBottom
and the isWrapping
property once when the widget is created. Remove the code from the resizeEvent
.
Also you can look at the layoutMode
property for the performance purposes.
Upvotes: 0
Reputation: 1364
I tried your code under Linux with Qt 5.5.1 and wrapping is fast and instant. What Qt version are you using? Qt 4.x has some performance issues under windows.
You can speed things up with NoAntialias
QFont fnt;
fnt.setStyleStrategy(QFont::NoAntialias);
ui->listView->setFont(fnt);
If your list grows bigger and you wan't to insert new data you will get bad performance. You should avoid QStandardItemModel for large sets of data.
Upvotes: 1