Re: Custom QGraphicsItems
You can put any item "on top" of your item by using your item as the parent item.
Cheers,
_
Re: Custom QGraphicsItems
Hey,
i tried:
Code:
painter->drawRect(tesst);
test->setPlainText("bla");
I created a rect and made this rect to the parent of my GraphicsTextItem. It dont work.
It would be nice if you could give me a small code example how u would do this. :)
kind regards
Re: Custom QGraphicsItems
That doesn't even compile.
I suggest to have a look at the documentation of QGraphicsTextItem and then think about what I could have possibly referred to when writing "using your item as the parent item"
Cheers,
_
Re: Custom QGraphicsItems
Hey,
i really really don't understand it. I always look into the documentation before i ask "stupid" questions. But im trying since 4 days only to draw editable text in a box. I can draw text with "painter->drawText(0,0,"Test");". I dont understand why i cant draw a QGraphicsTextItem. I also tried to creat an other QGraphicsItem and draw it in my PostIt QGraphicsItem. It dont work how i try it. I watched some tutorials in the internet, but they are just drawing some rects and triangles... . Im not an informatic student. Im doing this for fun and sometimes i just need more help than other people.
I dont want a comeplete code. I want to write it by my own because i like doing it, but at this point i can't do it without more help.
Please help me a bit more:).
kind regards
Re: Custom QGraphicsItems
Basically the items in a scene form a tree.
This tree is constructed by passing the pointer of one item as the "parent" of any number of other items.
These items become the "parent" item's "children".
Children are positioned relative to their parent, if you move such a parent item, the children move along with it.
After an items is drawn and its children are then drawn "on top" of it.
So you don't draw a text item on your item, you simply create a text item as a child of your item.
By passing your item as the parent to the text item's constructor, as I wrote in comment #2.
Cheers,
_
Re: Custom QGraphicsItems
Hey,
thank you so much thats exactly what i needed. I got one more question.
I created a second QGraphicsItem:
Code:
#ifndef DRAGDROPRECT_H
#define DRAGDROPRECT_H
#include <QGraphicsItem>
#include <QPainter>
#include <QRectF>
#include <QTextItem>
#include <QGraphicsTextItem>
{
public:
protected:
void dropEvent(QGraphicsSceneDragDropEvent *event);
};
#endif // DRAGDROPRECT
Code:
#include "../header/dragdroprect.h"
DragDropRect::DragDropRect()
{
setAcceptDrops(true);
}
QRectF DragDropRect
::boundingRect() const{ }
void DragDropRect::dropEvent(QGraphicsSceneDragDropEvent *event)
{
}
painter->setBrush(Qt::gray);
painter->drawRoundedRect(0,0,200,100,5,2);
}
and i tryed to get this into my PostIt item. So as i learned i took this dragdropRect and made PostIt to his parent in the PostIt constructor.
Code:
DragDropRect *rect = new DragDropRect(this);
Well it doesnt even compile.
I want to say thank you i really appreciate it that you spend your time to help me! :)
Re: Custom QGraphicsItems
Quote:
Originally Posted by
ReasyEasyPeasy
Well it doesnt even compile.
If you compare the signature of the constructor between the header and the source file, you will see they don't match (different number of arguments)
Looks at how you've done it in postit.cpp
Cheers,
_