Dear All!
How a way we can blink the QGraphicsTextItem in QGraphicsViewWidget?
Dear All!
How a way we can blink the QGraphicsTextItem in QGraphicsViewWidget?
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
A crazy idea is to toggle between hide and show in QGraphicsTextItem::timerEvent()
(it is a QObject).
But i really don't know how this works out to be.
The biggest difference between time and space is that you can't reuse time.
-- Merrick Furst
I wouldn't do that. Showing and hiding the item constantly would probably cause some internal data to be updated all the time. It is much simpler to subclass and simply not draw the item when it is to blink. This of course implies using a timer somewhere (not necessarily in the item itself).
Yeah, indeed this is the right approach to go
Just came up with following code.
Qt Code:
#include <QtGui> const int BlinkDelay = 128; { public: { startTimer(BlinkDelay); draw = true; } { if(!scene()) return; draw = !draw; update(); } { if( draw) { } } bool draw; }; int main(int argc, char *argv[]) { MyTextItem item(0); item.setPlainText("Hello there"); scene.addItem(&item); item.setPos(125, 100); view.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
The biggest difference between time and space is that you can't reuse time.
-- Merrick Furst
It'd be smarter to start and stop the timer from within QGraphicsItem::itemChange() when ItemVisibleChange occurs. There is no point in triggering the timer if the item is not visible.
The biggest difference between time and space is that you can't reuse time.
-- Merrick Furst
I mean kill the timer when item is hidden and start it again when it is shown. The itemChanged() method provides needed data.
How comes startTimer and timerEvent are available in MyTextItem even though it and its ancestors do not inherit from QObject? and it is only QObject that provides these methods.
I am pretty confused about the fact that the code compiles at all!
QGraphicsTextItem inherits QObject.
Look QGraphicsTextItem
The biggest difference between time and space is that you can't reuse time.
-- Merrick Furst
Bookmarks