How to identify boundingbox size changes in QGraphicsTextItem ?
-
While editing the content of QGraphicsTextItem, bounding box size changes. I need to perform some action , if bounding box size changes. I don't find any signal available in QGraphicsTextItem which gets emitted on bounding box change. Is there any other way to get update on boundingbox size changes ?
-
@Sridharan Of course you do not get compiler error!
That's why I said that you should switch to Qt5 connect syntax!Again, do you see the issue here: connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged)); ?
@jsulm
[solved]Thanks. I have corrected it to,
QGraphicsTextItem* textItem = new QGraphicsTextItem("New user");
textItem->setFlag(QGraphicsItem::ItemIsMovable);
textItem->setFlag(QGraphicsItem::ItemIsSelectable);
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);connect(textItem->document(), &QTextDocument::contentsChanged, this, &MainWindow::textcontentsChanged);
It's working now.
-
While editing the content of QGraphicsTextItem, bounding box size changes. I need to perform some action , if bounding box size changes. I don't find any signal available in QGraphicsTextItem which gets emitted on bounding box change. Is there any other way to get update on boundingbox size changes ?
@Sridharan
Since I see various...Changed()signals for e.g. position change but not size change, I can only think: save the item/bounding box size before the editing, compare it after the editing, emit your own signal if they are different?See also Detecting when a QGraphicsItem's boundingRect has changed or QGraphicsItem::itemChange notified for position change but not for size change, but I don't think they tell anything different.
-
@Sridharan
Since I see various...Changed()signals for e.g. position change but not size change, I can only think: save the item/bounding box size before the editing, compare it after the editing, emit your own signal if they are different?See also Detecting when a QGraphicsItem's boundingRect has changed or QGraphicsItem::itemChange notified for position change but not for size change, but I don't think they tell anything different.
I have tried idea provided in your 1st link, connect contentsChanged() signal to my own slot ( textcontentsChanged ) . By my slot is not getting executed. Attached my code below, anything wrong here ?
QGraphicsTextItem* textItem = new QGraphicsTextItem("New user"); textItem->setFlag(QGraphicsItem::ItemIsMovable); textItem->setFlag(QGraphicsItem::ItemIsSelectable); textItem->setTextInteractionFlags(Qt::TextEditorInteraction); QTextDocument* document = textItem->document(); connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged)); -
I have tried idea provided in your 1st link, connect contentsChanged() signal to my own slot ( textcontentsChanged ) . By my slot is not getting executed. Attached my code below, anything wrong here ?
QGraphicsTextItem* textItem = new QGraphicsTextItem("New user"); textItem->setFlag(QGraphicsItem::ItemIsMovable); textItem->setFlag(QGraphicsItem::ItemIsSelectable); textItem->setTextInteractionFlags(Qt::TextEditorInteraction); QTextDocument* document = textItem->document(); connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged));@Sridharan said in How to identify boundingbox size changes in QGraphicsTextItem ?:
connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged));
Do you see what is wrong here?
You should use Qt5 connect syntax to get compiler errors if your connect statement is wrong. -
@Sridharan said in How to identify boundingbox size changes in QGraphicsTextItem ?:
connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged));
Do you see what is wrong here?
You should use Qt5 connect syntax to get compiler errors if your connect statement is wrong. -
@jsulm
No compilation error. Problem is my slot function is not executed when i modify text@Sridharan Of course you do not get compiler error!
That's why I said that you should switch to Qt5 connect syntax!Again, do you see the issue here: connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged)); ?
-
@jsulm
No compilation error. Problem is my slot function is not executed when i modify text@Sridharan
As @jsulm says. Which is why you should switch to https://wiki.qt.io/New_Signal_Slot_Syntax. It's not even "new" now, the syntax you are using is like a decade old, and is the cause of exactly this kind of error, which we have to keep pointing out to people when they get it wrong over and over.... -
@Sridharan Of course you do not get compiler error!
That's why I said that you should switch to Qt5 connect syntax!Again, do you see the issue here: connect(document, SIGNAL(contentsChanged()), this, SLOT(textcontentsChanged)); ?
@jsulm
[solved]Thanks. I have corrected it to,
QGraphicsTextItem* textItem = new QGraphicsTextItem("New user");
textItem->setFlag(QGraphicsItem::ItemIsMovable);
textItem->setFlag(QGraphicsItem::ItemIsSelectable);
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);connect(textItem->document(), &QTextDocument::contentsChanged, this, &MainWindow::textcontentsChanged);
It's working now.