Hi, I have a class that inherits from the QGraphicsSimpleTextItem class. I cannot figure out how to make the background change when this happens. Right now, I figured out that by changing the pen I can make the text outlines change:
text_item->setPen(QPen(QColor(Qt::black)));
To copy to clipboard, switch view to plain text mode
Running this code will change the outlines of the text in text_item, but I want a more dramatic change. I am looking for a way to replace that line with something that will change the background of my text_item when I choose. I tried overwriting the paint() function inherited from QGraphicsItem like so:
{
painter->setBrush(brush);
painter->drawRect(0,0,50,50);
this
->setPen
(QPen(Qt
::black));
}
void MyTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QBrush brush(Qt::white);
painter->setBrush(brush);
painter->drawRect(0,0,50,50);
this->setPen(QPen(Qt::black));
}
To copy to clipboard, switch view to plain text mode
The first three lines of the function paint a white rectangle as the background (which is what I am aiming for), but setting the pen does nothing to display the text. So, I can either have the text with no change in background, or when I try to change the background the text doesn't show up. The fourth line in that function seems to do nothing. Is there any way I can have this class still display the text but also be able to change the background?
Thanks in advance,
psychocowtipper
Bookmarks