Hi,
I've got an editable QComboBox which I put into a QGraphicsScene. The graphics scene gets visualised by a QGraphicsView which itself gets added to another QGraphicsScene. This second graphics scene gets again visualised by a second QGraphicsView. (see code below)
I've got a few issues with this configuration:
1. I have to set the cache mode to ItemCoordinateCache or DeviceCoordinateCache in order to see the drop down list of the combo box. Not a major issue so far, but why is this necessary?
2. When hoovering with the mouse over the edit field of the combo box then I expect the mouse cursor to change into the caret symbol, this does not happen.
3. When clicking once into the edit field the text caret does not appear, typing however changes the text, so the edit field 'somehow' gets the keyboard events.
Has anyone any idea what I have to do so that the combo box behaves as if it would be added directly into the outer scene? Any idea or suggestion is welcome and appreciated.
Following the sourcecode which shows the described behaviour. This is just a simplified example of what I want to do. Later I want to use all kind of other widgets and dialogs for where I use the combo box at the moment.
#include <QApplication>
#include <QComboBox>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsProxyWidget>
int main(int argc, char *argv[])
{
combo->addItem("First");
combo->addItem("Second");
combo->setEditable(true);
combo->setObjectName("the combo box");
// Create the outer scene and view, it may contain several 'inner' graphics
// views and scenes.
outerScene->setObjectName("the outer scene");
outerView->setObjectName("the outer view");
// The outer graphics view is our 'main window'
outerView->show();
// if set to 0 then the combo box gets added directly into the outer scene,
// if set to 1 then the combo box gets added into a graphics scene which
// gets visualised by a graphics view added to the outer scene.
if (0)
{
// In this scenario we add the combo box into the outer scene.
outerScene->addWidget(combo);
}
else
{
// In the second scenario we add another QGraphicsScene and QGraphicsView,
// the inner scene and inner view. The inner view gets added to the outer
// scene using a QProxyWidget. The combo box now gets added to this inner
// scene.
// Adding the combo box to its 'own' scene allows us to do all kind of
// funny things like scaling, rotation, etc.
innerScene->setObjectName("the inner scene");
innerView->setObjectName("the inner view");
QGraphicsProxyWidget* innerViewProxy = outerScene->addWidget(innerView);
innerViewProxy->setObjectName("the inner view proxy");
QGraphicsProxyWidget* proxy = innerScene->addWidget(combo);
proxy->setObjectName("the combo proxy");
// Seems like we have to set the cache mode to Item or DeviceCorrdinateCaching
// in order to see the drop down list.
//proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
innerScene->setActiveWindow(proxy);
// Turn the combo box upside down and scale it a bit. It gets rotated and
// scaled independent of objects in the outer scene, Nice!
innerView->scale(2.0, 2.0);
innerView->rotate(180.0);
}
return a.exec();
}
#include <QApplication>
#include <QComboBox>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsProxyWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QComboBox* combo = new QComboBox();
combo->addItem("First");
combo->addItem("Second");
combo->setEditable(true);
combo->setObjectName("the combo box");
// Create the outer scene and view, it may contain several 'inner' graphics
// views and scenes.
QGraphicsScene* outerScene = new QGraphicsScene();
outerScene->setObjectName("the outer scene");
QGraphicsView* outerView = new QGraphicsView(outerScene);
outerView->setObjectName("the outer view");
// The outer graphics view is our 'main window'
outerView->show();
// if set to 0 then the combo box gets added directly into the outer scene,
// if set to 1 then the combo box gets added into a graphics scene which
// gets visualised by a graphics view added to the outer scene.
if (0)
{
// In this scenario we add the combo box into the outer scene.
outerScene->addWidget(combo);
}
else
{
// In the second scenario we add another QGraphicsScene and QGraphicsView,
// the inner scene and inner view. The inner view gets added to the outer
// scene using a QProxyWidget. The combo box now gets added to this inner
// scene.
// Adding the combo box to its 'own' scene allows us to do all kind of
// funny things like scaling, rotation, etc.
QGraphicsScene* innerScene = new QGraphicsScene();
innerScene->setObjectName("the inner scene");
QGraphicsView* innerView = new QGraphicsView(innerScene);
innerView->setObjectName("the inner view");
QGraphicsProxyWidget* innerViewProxy = outerScene->addWidget(innerView);
innerViewProxy->setObjectName("the inner view proxy");
QGraphicsProxyWidget* proxy = innerScene->addWidget(combo);
proxy->setObjectName("the combo proxy");
// Seems like we have to set the cache mode to Item or DeviceCorrdinateCaching
// in order to see the drop down list.
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
//proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
innerScene->setActiveWindow(proxy);
// Turn the combo box upside down and scale it a bit. It gets rotated and
// scaled independent of objects in the outer scene, Nice!
innerView->scale(2.0, 2.0);
innerView->rotate(180.0);
}
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Thank You!
Peer
Bookmarks