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
) :{
ui.setupUi(this);
connect(ui.actionNew, SIGNAL(triggered()), this, SLOT(newTab()));
}
void MainWindow::newTab()
{
item->setTextInteractionFlags(Qt::TextEditorInteraction);
scene->addItem(item);
ui.tabWidget->addTab(view, "Scene");
}
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");
}
To copy to clipboard, switch view to plain text mode
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.
main.cpp
MainWindow.ui
MainWindow.h
MainWindow.cpp
Bookmarks