Results 1 to 7 of 7

Thread: Focus/Activation problem for widget in nested QGraphicsScenes

  1. #1
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Focus/Activation problem for widget in nested QGraphicsScenes

    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.
    Qt Code:
    1. #include <QApplication>
    2. #include <QComboBox>
    3. #include <QGraphicsScene>
    4. #include <QGraphicsView>
    5. #include <QGraphicsProxyWidget>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. QComboBox* combo = new QComboBox();
    12. combo->addItem("First");
    13. combo->addItem("Second");
    14. combo->setEditable(true);
    15. combo->setObjectName("the combo box");
    16.  
    17. // Create the outer scene and view, it may contain several 'inner' graphics
    18. // views and scenes.
    19. QGraphicsScene* outerScene = new QGraphicsScene();
    20. outerScene->setObjectName("the outer scene");
    21. QGraphicsView* outerView = new QGraphicsView(outerScene);
    22. outerView->setObjectName("the outer view");
    23.  
    24. // The outer graphics view is our 'main window'
    25. outerView->show();
    26.  
    27. // if set to 0 then the combo box gets added directly into the outer scene,
    28. // if set to 1 then the combo box gets added into a graphics scene which
    29. // gets visualised by a graphics view added to the outer scene.
    30. if (0)
    31. {
    32. // In this scenario we add the combo box into the outer scene.
    33. outerScene->addWidget(combo);
    34. }
    35. else
    36. {
    37. // In the second scenario we add another QGraphicsScene and QGraphicsView,
    38. // the inner scene and inner view. The inner view gets added to the outer
    39. // scene using a QProxyWidget. The combo box now gets added to this inner
    40. // scene.
    41. // Adding the combo box to its 'own' scene allows us to do all kind of
    42. // funny things like scaling, rotation, etc.
    43.  
    44. QGraphicsScene* innerScene = new QGraphicsScene();
    45. innerScene->setObjectName("the inner scene");
    46. QGraphicsView* innerView = new QGraphicsView(innerScene);
    47. innerView->setObjectName("the inner view");
    48.  
    49. QGraphicsProxyWidget* innerViewProxy = outerScene->addWidget(innerView);
    50. innerViewProxy->setObjectName("the inner view proxy");
    51.  
    52. QGraphicsProxyWidget* proxy = innerScene->addWidget(combo);
    53. proxy->setObjectName("the combo proxy");
    54.  
    55. // Seems like we have to set the cache mode to Item or DeviceCorrdinateCaching
    56. // in order to see the drop down list.
    57. proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
    58. //proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    59.  
    60. innerScene->setActiveWindow(proxy);
    61.  
    62. // Turn the combo box upside down and scale it a bit. It gets rotated and
    63. // scaled independent of objects in the outer scene, Nice!
    64. innerView->scale(2.0, 2.0);
    65. innerView->rotate(180.0);
    66. }
    67.  
    68. return a.exec();
    69. }
    To copy to clipboard, switch view to plain text mode 

    Thank You!
    Peer

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Focus/Activation problem for widget in nested QGraphicsScenes

    I would question your approach. To me it seems very wrong.

    You don't need scene in the scene to be able to manipulate widgets.
    You can do whatever you want to the proxy object.

    Qt Code:
    1. // part of your example:
    2. if(1)
    3. {
    4. // In this scenario we add the combo box into the outer scene.
    5. QGraphicsProxyWidget* proxy = outerScene->addWidget(combo);
    6. proxy->rotate( 90 );
    7. proxy->scale(2.0, 2.0);
    8. }
    To copy to clipboard, switch view to plain text mode 
    This will do all you want (I'm guessing) without issues you're having.

    Unless there's another reason why you do the nesting but I can't see anything convincing.

  3. The following user says thank you to Spitfire for this useful post:

    peers (9th May 2012)

  4. #3
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Focus/Activation problem for widget in nested QGraphicsScenes

    Thanks a lot for your reply Spitfire.

    I missed that I can do the transformations on the proxy, thanks for telling me about it.

    However this solves only one part of what I want to do. I also need to display several items painting using OpenGL, and I need to display them in parallel. Because I cannot add QGLWidgets to a proxy, I have to use several scenes, one for each OpenGL item. All items, OpenGL and 'normal' items have to appear in the same scene at the end.

    If you know about a better way of getting what I need then I would love to here about it

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Focus/Activation problem for widget in nested QGraphicsScenes

    I know almost nothing about OpenGL, but the first thing that springs to my mind is: use OpenGL only
    You should be able to add any widget to gl scene and render it in single view.

    Like I've said - I've never done it, but maybe this article will help you.

  6. The following user says thank you to Spitfire for this useful post:

    peers (9th May 2012)

  7. #5
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Focus/Activation problem for widget in nested QGraphicsScenes

    Quote Originally Posted by Spitfire View Post
    You should be able to add any widget to gl scene and render it in single view.

    Like I've said - I've never done it, but maybe this article will help you.
    What do you mean with single view?

    I know that article, however as I understood it I can only render one openGL scene per graphics scene. But because I need to show several openGL scenes at once I think I need more than one graphics scene. And because I would like to handle these 'inner' scenes like any QGraphicsItem (thats why I add the associated views to the outer scene via a proxy) I need the 'nested' scenes.

    Thanks anyway

  8. #6
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Focus/Activation problem for widget in nested QGraphicsScenes

    What I can't figure out is why you need many scenes?
    It doesn't seem right to me.

    From what I see you want to have gl and q items and widgets in a scene.
    have signle gl scene, add what you want to it and that's it. Where you get other scenes? Is it imposed on you?
    If you want to manipulate group of elements together, create a widget from that elements, or group them together, or use layout in the scene.

    You didn't say what you're trying to do but I'm guessing that nested scenes will be troublesome in many ways and you should think about different solution.

    Anyway, good luck

  9. #7
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Focus/Activation problem for widget in nested QGraphicsScenes

    I am working on a system which has to display measurement data. This data is of different kind, curves, images, etc., some of it we visualise using OpenGL. The reason for several OpenGL scenes is that we display data from multiple sources in parallel, sometimes we display data from one source in more than one scene because the visualisation of the same data can be done different to see different things in it. This is the motivation for wanting to have different OpenGL scenes in an 'outer' scene.

    The Graphics Scene/View framework provides all the flexibility we need now and it provides enough flexibility for what we want in the future, that is why, at the moment, I try to find out how we can realise our current application using this framework. The only problem I have so far is the described problem with multiple OpenGl scene.

    What I am doing now is to evaluate whether we really need OpenGL. Before we needed it because we had to display image data with a high update rate. The system was designed and first developed almost 10 years ago, that time OpenGL was what we needed. Now, however, I think we could get away with using a QImage as off buffer and then, in the paint routine of a QGraphicsItem, paint modified parts of the QImage. So far my first tests are promising.

    Regards
    Peer

Similar Threads

  1. Multi Widget focus problem with QListView in s60
    By ericleopard in forum Qt Programming
    Replies: 0
    Last Post: 11th July 2011, 04:29
  2. Problem with nested dock (Border Related).
    By pastispast in forum Qt Programming
    Replies: 6
    Last Post: 13th May 2011, 06:49
  3. Replies: 3
    Last Post: 2nd August 2010, 10:12
  4. Replies: 8
    Last Post: 9th July 2010, 00:37
  5. Qt4 widget and nested layout issue.
    By bunjee in forum Qt Programming
    Replies: 12
    Last Post: 18th January 2007, 20:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.