Can't adjust font size of QGraphicsTextItem in QGraphicsRectItem
Hi,
I created a custom QGraphicsRectItem to allow me to handle mouse events which works fine. The issue I'm having is when I try to set the font of a QGraphicsTextItem which happens to be in my custom QGraphicsRectItem, it won't change I can't even change the text width. Below is a sample code.
Code:
CustomRect:
CustomRectItem::CustomRectItem()
{
}
//subclass QGraphicsRectItem to allow mouse events
{
int xyCellSize = 20;
if(event->isAccepted())
{
if(event->button() == Qt::LeftButton)
{
int x = ((event->scenePos().x() - sceneStartCornerX_) / xyCellSize) + 2; //add one to accomodate the cell for the pingee and pinger text - 32
int y = ((event->scenePos().y() - sceneStartCornerY_) / xyCellSize) + 2; // 217
Q_EMIT sendRectClicked(y, x);
}
}
}
void CustomRectItem::getViewCoordinates(int x, int y)
{
sceneStartCornerX_ = x;
sceneStartCornerY_ = y;
}
------------------------------
In my main to change the fonts size:
Code:
CustomRectItem *rect = new CustomRectItem;
rect->setRect(12 + (XY_CELL_SIZE * column), sceneStartCornerY_ + (XY_CELL_SIZE * rowPlacement), XY_CELL_SIZE, XY_CELL_SIZE);
appIDText->setPos(12 + (XY_CELL_SIZE * column), sceneStartCornerY_ + (XY_CELL_SIZE * rowPlacement));
QFont times
("Times",
10);
appIDText->setFont(times);
appIDText
->setPlainText
(QString::number(appID
));
scene->addItem(rect);
The text is in the rect just can't change the font size. Can someone please explain to me what I'm doing wrong?
Thanks!
Re: Can't adjust font size of QGraphicsTextItem in QGraphicsRectItem
Quote:
Originally Posted by
leinad
Hi,
I created a custom QGraphicsRectItem to allow me to handle mouse events which works fine. The issue I'm having is when I try to set the font of a QGraphicsTextItem which happens to be in my custom QGraphicsRectItem, it won't change I can't even change the text width. Below is a sample code.
CustomRect:
CustomRectItem::CustomRectItem()
{
}
//subclass QGraphicsRectItem to allow mouse events
void CustomRectItem::mousePressEvent(QGraphicsSceneMous eEvent *event)
{
int xyCellSize = 20;
if(event->isAccepted())
{
if(event->button() == Qt::LeftButton)
{
int x = ((event->scenePos().x() - sceneStartCornerX_) / xyCellSize) + 2; //add one to accomodate the cell for the pingee and pinger text - 32
int y = ((event->scenePos().y() - sceneStartCornerY_) / xyCellSize) + 2; // 217
Q_EMIT sendRectClicked(y, x);
}
}
}
void CustomRectItem::getViewCoordinates(int x, int y)
{
sceneStartCornerX_ = x;
sceneStartCornerY_ = y;
}
------------------------------
In my main to change the fonts size:
CustomRectItem *rect = new CustomRectItem;
rect->setRect(12 + (XY_CELL_SIZE * column), sceneStartCornerY_ + (XY_CELL_SIZE * rowPlacement), XY_CELL_SIZE, XY_CELL_SIZE);
QGraphicsTextItem *appIDText = new QGraphicsTextItem(rect);
appIDText->setPos(12 + (XY_CELL_SIZE * column), sceneStartCornerY_ + (XY_CELL_SIZE * rowPlacement));
QFont times("Times", 10);
appIDText->setFont(times);
appIDText->setPlainText(QString::number(appID));
scene->addItem(rect);
The text is in the rect just can't change the font size. Can someone please explain to me what I'm doing wrong?
Thanks!
No one has any ideas?
Re: Can't adjust font size of QGraphicsTextItem in QGraphicsRectItem
Have you set the QGraphicsItem::ItemIgnoresTransformations flag on your QGraphicsTextItem? This will prevent the QGraphicsRectItem from scaling the text according to its own scaling transformations (which are applied when the scene is fit into the view).
Quote:
No one has any ideas?
You should be a little more patient. This forum has been slow lately, and not everyone reads it every day.
Re: Can't adjust font size of QGraphicsTextItem in QGraphicsRectItem
Quote:
Originally Posted by
d_stranz
My apologies. I'll take a look at what you mentioned. Thanks.