English 中文(简体)
Qt QGraphics 增建项目
原标题:Qt QGraphicsScene slow adding items
  • 时间:2012-01-13 17:43:40
  •  标签:
  • c++
  • qt

我一直在努力使用QGraphicsScene,使用以下代码建立可沉积的电网:

int w = 5;
int h = 5;
//QRect r(0, 0, w*1680, h*800);
//scene->setSceneRect(r);
//scene->setBspTreeDepth(5);
//scene->setItemIndexMethod(QGraphicsScene::NoIndex);
QTime t;
for(long i = 0; i < 800; ++i) {
    t.restart();
    for(long j = 0; j < 1680; ++j) {
        QGraphicsItem *item = scene->addRect(j*w, i*h, w, h, pen, brush);
        item->setFlag(QGraphicsItem::ItemIsSelectable, true);
    }
    qDebug() << "Elapsed Time: " << t.elapsed();
}
//scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
setScene(scene);
//setSceneRect(0, 0, 200, 200);

从法典中可以看到,现场大约有100万个直径。 增加新项目的时间似乎增加了多产,而不是象以下网址所述的那样:。 详细文件。 我做的事情显然是错误的?

最佳回答

答案针对的是问题-固定电网下的评论中提到的特殊问题,在这些地方,各种电网电池可以“选择”。

这里的主要想法是,格罗克不成形,选择一个单元是“可”的。 一种想法是界定backgroundBrush property,QGraphicsScene,为你选用固定电网,或许使用简单的可操作的密码。 这是有效的,因为它只是现场的一个背景,没有生动的物体。

为使牢房能够选择,要看现场的 mo事,如果用户在现场某处点点点击,你就可以在适当地点制造你所希望的颜色。 这使你基本上能够有一个可以选择任何电池的无限网。

http://developer.qt.nokia.com/doc/qt-4.8/qgraphicsscene.html#eventFilter”rel=“nofollow”eventFilter 处理某些 mo事件的方法。 您现在可以通过打电话http://developer.qt.nokia.com/doc/qt-4.8/qobject.html#installEventFilter”rel=“nofollow”installEventFilter安装这一过滤器。 您的场面方法。

在您的<密码>-eventFilter方法中,你将主要研究模拟事件,视其立场,在现场的适当地点制造新的有色谱。

Hope this makes sense.

问题回答

IndexMethod to noIndex helps the items inclusion exercise. 见。 履历 Q ics 项目造成重大减速





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签