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
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