Hello guys,
I'd like to ask you a question about the Qt Graphics View Framework (Qt 4.3, MacOS X 10.4.10).
I created a custom class that inherits from QGraphicsItem, defined as follows:
#ifndef SIMTARGET_H
#define SIMTARGET_H
#include <QGraphicsItem>
#include <QString>
Q_OBJECT
public:
// Constructor
Sim_Target();
// itemChange() function
// Shape
// Tooltip
private:
signals:
void dragged();
};
#endif
#ifndef SIMTARGET_H
#define SIMTARGET_H
#include <QGraphicsItem>
#include <QString>
class Sim_Target : public QObject, public QGraphicsItem {
Q_OBJECT
public:
// Constructor
Sim_Target();
// itemChange() function
QVariant itemChange(GraphicsItemChange change, const QVariant & value);
// Shape
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
// Tooltip
QString str_target_tooltip;
private:
QColor color;
signals:
void dragged();
};
#endif
To copy to clipboard, switch view to plain text mode
In a slot belonging to my application's main window, I create an instance of the object and I insert it into the scene:
// Create the target and add it to the scene
simulationTarget = new Sim_Target;
graphScene_Scene->addItem(simulationTarget);
// Create the target and add it to the scene
simulationTarget = new Sim_Target;
graphScene_Scene->addItem(simulationTarget);
To copy to clipboard, switch view to plain text mode
then I perform some basic operations on the object, trying to move it:
simulationTarget->setPos(10,30);
for (int counter=1; counter<1000; counter++) {
simulationTarget->setPos(simulationTarget->x()+1, simulationTarget->y());
}
simulationTarget->setPos(10,30);
for (int counter=1; counter<1000; counter++) {
simulationTarget->setPos(simulationTarget->x()+1, simulationTarget->y());
}
To copy to clipboard, switch view to plain text mode
The problem is that, during the execution of the for-cycle, I cannot see the object moving. At the end of the for-cycle, of course, when the application's control returns to the event loop, I see the object occupying the expected position (ie, the movement was performed correctly).
I think I have to call some functions that force the continuos repainting of the object after each movement. But looking at the documentation I didn't understand which is the function I should call. Again, while the for-cycle is executing, I'd like to be able to control the mouse (for example to press the button that quits my application); instead, until the program doesn't reach the event loop, I can only see my mouse cursor as a spinning beachball (the Mac's equivalent for the Windows' hourglass).
Could someone offer me some suggests, please? :-(
Bookmarks