hi friends,
how to show time in a graphicsItem
ex: inside a graphicsRectItem i want to show the current date and the time ... like digital clock example ....
how can i use timer event in a painted text object ...?
please help me ...
hi friends,
how to show time in a graphicsItem
ex: inside a graphicsRectItem i want to show the current date and the time ... like digital clock example ....
how can i use timer event in a painted text object ...?
please help me ...
Beside performance considerations you could create your own graphic item like
and then you have signals und slots and you could simply use a timer to trigger the paint method to update the clock. If you want better performance only update the region rect with the clock.Qt Code:
Q_OBJECTTo copy to clipboard, switch view to plain text mode
EDIT: Or use "stacked" items: "subitem" is showing the time and is a child of your original item and lay out above it.
thanks for the reply ...
is the
QGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);is like QPaintEvent() ... ? can i use update there ...?
can u help me how to update a particular region rect()
Last edited by wagmare; 22nd April 2009 at 14:54.
As you write you want to use a QGraphicsRectItem, so subclass that and do:
Qt Code:
//... MyGraphicsRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { // here you can use painter freely: painter->draw... }To copy to clipboard, switch view to plain text mode
For only update a certain rect use QGraphicsItem::update(const QRectF & rect = QRectF()) and implement the region in your paint method.
wagmare (22nd April 2009)
thanks ,
i complete updating the area as
starting a timer of 1000 msec
my code
Qt Code:
{ painter->setPen(pen); painter->drawRoundRect(rect()); if(cond){ draw(painter); timer->start(1000); } }To copy to clipboard, switch view to plain text mode
Qt Code:
{ painter->drawText(value,text); painter->drawText(value2, text2); }To copy to clipboard, switch view to plain text mode
this is timer slot
Qt Code:
:slotUpdate() { update(0,0,29,37); }To copy to clipboard, switch view to plain text mode
and it is working ... but is it a right way ...
You could very well use QGraphicsTextItem and on timeout of the timer, simply set the text of the text item with QTime::currentTime().toString()![]()
wagmare (24th April 2009)
Hi,
all what I am going to say, I never have done myself, but this is how I would optimize:
- Store a QRectF (m_dateTimeRect) in which you display date and time
- Check in paint if QStyleOptionGraphicsItem::exposedRect() equal m_dateTimeRect -> only draw the time. not the border...
- Use QPointF value(28, 35); and QPointF value2(15, 55); directly...
Lykurg
wagmare (24th April 2009)
but is it possible to add an QGraphicsItem in painter inside the paint() function ...
You have following opportunities:
- Do all the stuff by yourself inside the paint
- Let Qt do some things for you.
If the last, decide from which QGraphicsXXXItem you want subclass. As I have understand you, you want a border and inside date and time. So I would subclass MyGraphicsRectItem as previously written. Then you don't have to draw your border yourself. Use
instead ofQt Code:
To copy to clipboard, switch view to plain text modeQt Code:
painter->drawRoundRect(rect());To copy to clipboard, switch view to plain text mode
Or use a text item and set date and time via setText and draw the border yourself...
Lykurg
Bookmarks