Active QGraphicsScene on application startup
-
Hi, I have an application, which contains QTabWidget with tabs. In this tab contains widget with two childrens: QGraphicScene widget with some QGraphicsTextItem inside and QGraphicView for this scene.
So, it's very usfull have keyboard focus in the text element inside tab to starts enter text immideatly after application startup (like notepad: you run the app and you starts write text without using mouse to activate window).
I could have this behavior with QPlainTextEdit in one of QTabWidget tabs: for this I set focus on the QPlainTextEditor.
But for I can't do it for QGraphicItem, because I can't focus on this element, because scene of this element don't active. And as I see, scene don't active, because window don't active.
So, could I active QGraphicsScene on startup? -
Hi
Tried fast sample with
https://www.bogotobogo.com/Qt/Qt5_QGraphicsView_QGraphicsScene.php
and did
ui->graphicsView->setFocus();
rectangle->setSelected(true);and it does start up with view has focus and rectangle selected.
Is that what you mean ?
test project
https://www.dropbox.com/s/tc93kbi5w3c5and/GSceneTest.zip?dl=0 -
@mrjj Yes, almost: text graphic obejct instead of ractangle. But thanks for this suggestion, it's was very usefull, because I found problem.
My problem was that I set focus on scene widget before adding the widget to tab widget. As I see, qt clear focus from the scene widget after adding to tab widget.
I have added setting focus on scene after addTab statement and now it works.