【发布时间】:2019-11-08 02:23:05
【问题描述】:
总结
我在 SUSE 64 位下使用 qt 4.8.7
我有 2 个刷新率不同的 QGraphicsItem。但是当我在其中一个上调用“update()”时,对它们两个都调用了“paint()”。所以这两个项目的真实刷新率是两个刷新率的最高公因数。
我想独立调用paint()方法... 我不知道这个问题来自哪里以及如何解决它(我试图调用 QGraphicsItem::update(QRectF(//item_dimensions//))" 而不是 QGraphicsItem::update() 但问题是一样的)
简化代码
toto.hpp
class Toto : public QObject, QGraphicsItem
{
Q_OBJECT
public:
Toto(QString name)
{
m_name = name;
}
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* = NULL)
{
QTextStream(stdout) << "paint : " << m_name << endl;
//other stuff
}
public slots:
void updateSlot()
{
QTextStream(stdout) << "\nupdate : " << m_name << endl;
QGraphicsItem::update();
}
private:
QString m_name;
}
main.cpp
Toto1 = new Toto("toto_1");
Toto2 = new Toto("toto_2");
QTimer *timer1 = new QTimer(500);
QTimer *timer2 = new QTimer(2000);
connect(timer1, SIGNAL(timeout()), toto1, SLOT(updateSlot()));
connect(timer2, SIGNAL(timeout()), toto2, SLOT(updateSlot()));
timer1->start();
timer2->start();
预期输出:
toto_1 update
toto_1 paint
toto_1 update
toto_1 paint
toto_1 update
toto_1 paint
toto_1 update
toto_1 paint
toto_2 update
toto_2 paint
toto_1 每 500ms 更新一次,toto_2 每 2000ms 更新一次
我得到了什么:
toto_1 update
toto_1 paint
toto_2 paint
toto_1 update
toto_1 paint
toto_2 paint
toto_1 update
toto_1 paint
toto_2 paint
toto_1 update
toto_1 paint
toto_2 paint
toto_2 update
toto_1 paint
toto_2 paint
toto_1 和 toto_2 都每 500 毫秒更新一次
感谢您的帮助!
【问题讨论】:
-
你能告诉我你的 Toto::boundingRect() 的实现吗?
标签: c++ qt qt4 qgraphicsitem