zhonghua

C++博客 首页 新随笔 联系 聚合 管理
  72 Posts :: 1 Stories :: 4 Comments :: 0 Trackbacks

#

当你使用QStandardItemModel(model)与QTableView显示数据时, 如果数据量比较大, 如几千上万条, 每次给model填充数据时, 只是使用model->clear()来清空数据, 然后再填充, 速度会非常的慢. 但如果是使用delete model; model = new QStandardItemModel()显示的删除model, 然后再创建一个model, 这样显示速度会非常的快, 不知何故.
例子:
int main(int argc, char *argv[]) {
QApplication app(argc, argv);

QStandardItemModel *model = new QStandardItemModel();
QTableView *table = new QTableView();

// 如果事先给 table设置了 model而不预指定好要存储的数据的行数,则会非常慢
// table->setModel(model); /// [[1]]
// model->setRowCount(1000); /// [[1]]

model->setColumnCount(14);

for (int i = 0; i < 1000; ++i) {
model->setItem(i, 0, new QStandardItem("1"));
model->setItem(i, 1, new QStandardItem("2"));
model->setItem(i, 2, new QStandardItem("3"));
model->setItem(i, 3, new QStandardItem("4"));
model->setItem(i, 4, new QStandardItem("5"));
model->setItem(i, 5, new QStandardItem("6"));
model->setItem(i, 6, new QStandardItem("7"));
model->setItem(i, 7, new QStandardItem("8"));
model->setItem(i, 8, new QStandardItem("9"));
model->setItem(i, 9, new QStandardItem("10"));
model->setItem(i, 10, new QStandardItem("11"));
model->setItem(i, 11, new QStandardItem("12"));
model->setItem(i, 12, new QStandardItem("13"));
model->setItem(i, 13, new QStandardItem("14"));
}
posted @ 2012-03-22 16:05 米米 阅读(1323) | 评论 (0)编辑 收藏

I'm building my own custom event and I want to just put this out there to
see if anyone is offended by the way I use the registerEventType function
(since I can't find any specific info on how to use it).  I think it make
sense... but I've never casted a new value into a predefined enum... and I
fear change.

ShapeAnimationEvent.h:

#ifndef SHAPE_ANIMATION_EVENT_H
#define SHAPE_ANIMATION_EVENT_H

#include <QEvent>
#include <QVariant>

class ShapeAnimationEvent : public QEvent
{
public:
    static const QEvent::Type JUMP_TO_TIME;

    ShapeAnimationEvent(QEvent::Type type, QVariant data);
    QVariant data() const;

private:
    QVariant m_data;

};

#endif

ShapeAnimationEvent.cpp:

#include "ShapeAnimationEvent.h"

const QEvent::Type ShapeAnimationEvent::JUMP_TO_TIME =
(QEvent::Type)QEvent::registerEventType();

ShapeAnimationEvent::ShapeAnimationEvent(QEvent::Type type, QVariant data) :
QEvent(type), m_data(data)
{

}

QVariant ShapeAnimationEvent::data() const
{
    return m_data;
}

Thanks,
Brian!
posted @ 2012-03-22 14:38 米米 阅读(945) | 评论 (0)编辑 收藏

仅列出标题
共8页: 1 2 3 4 5 6 7 8