PDA

View Full Version : Text interaction with QGraphicsTextItem in multiple scenes and views



joekemp
2nd June 2011, 13:35
I have multiple QGraphicsView items, each shown in a tab of an QTabWidget. Each view has its own QGraphicsScene.

I have a problem with QGraphicsTextItem items in all views created after the first one. The problem is when I attempt to edit them - I have no text caret and the dashed border is also absent. However, I can still edit the item.

I have reproduced the issue in the code below:


MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags) :
QMainWindow(parent, flags)
{
ui.setupUi(this);
connect(ui.actionNew, SIGNAL(triggered()), this, SLOT(newTab()));
}

void MainWindow::newTab()
{
QGraphicsScene* scene = new QGraphicsScene(this);

QGraphicsTextItem* item = new QGraphicsTextItem("Hello World!");
item->setTextInteractionFlags(Qt::TextEditorInteraction) ;
scene->addItem(item);

QGraphicsView* view = new QGraphicsView(scene, ui.tabWidget);
ui.tabWidget->addTab(view, "Scene");
}


Interestingly, if I call newTab() multiple times inside the MainWindow's constructor, each view behaves as expected without the issue. However, all subsequent tabs suffer from text editing issue.

Thanks in advance for any help anyone can give me. All files attached below.

6510
6511
6512
6513

joyer83
2nd June 2011, 14:39
According to QTabWidget's documentation you're not supposed to give a parent for widgets which you add as tabs to it.
So, try this if it might help:


QGraphicsView* view = new QGraphicsView(scene /*, ui.tabWidget*/ );

joekemp
3rd June 2011, 10:17
Thanks joyer. Doesn't seem to fix the problem. I think it is the bug below:
http://bugreports.qt.nokia.com/browse/QTBUG-18961

Anybody have an idea how I can fix it as the software I am working on needs to be released soon?

stampede
3rd June 2011, 10:28
Which Qt version are you using ? This bug seems to affect version 4.7.0, maybe you can just downgrade to 4.6.x ?

joekemp
3rd June 2011, 11:35
Hi stampede. I'm using version 4.7.1. I tried version 4.6.3 as you recommended, but the bug is still there.