Results 1 to 9 of 9

Thread: Problem with QGraphicsScene, QGraphicsProxyWidget, and setting widget focus

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QGraphicsScene, QGraphicsProxyWidget, and setting widget focus

    Oh and have you set the Qgraphicsitem flag ItemIsFocusable?

    proxy.setFlag(QGraphicsItem::ItemIsFocusable,true) ;

    Joh

  2. #2
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QGraphicsScene, QGraphicsProxyWidget, and setting widget focus

    Hi Joh,

    Yep I tried setting the ItemIsFocusable flag.

    (And yep I tried removing the mouse move event handlers completely.)

    Oh and have you set the Qgraphicsitem flag ItemIsFocusable?

    proxy.setFlag(QGraphicsItem::ItemIsFocusable,true) ;

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QGraphicsScene, QGraphicsProxyWidget, and setting widget focus

    Could you create a small test project, just a view, scene, and add a widget to it and try handling its mouse events.

    No time to do it myself, right now.

    Joh

  4. #4
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QGraphicsScene, QGraphicsProxyWidget, and setting widget focus

    Yep, I'll try creating a small test project this week. But first I'll try moving all mouse/keyboard events out of QGraphicsView and into QGraphicsScene.

    Ian

  5. #5
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with QGraphicsScene, QGraphicsProxyWidget, and setting widget focus

    OK, finally got the code working correctly.

    In terms of focus, the key piece of missing functionality that I added is checking for a focus item in QGraphicsScene event handlers. Specifically, if the graphics scene has a focus item, the code ignores the event and instead calls the default QGraphicsScene event handler. The mouse move event excerpt is below.

    Qt Code:
    1. void MyGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
    2. if(!focusItem()) { //only handle events if no proxy items are in focus
    3. //rotate openGL scene, etc
    4. }
    5. else {
    6. QGraphicsScene::mouseMoveEvent(event); //call this so that proxy widget will receive event
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Before (when the code did not check for a focus item) the openGL scene would rotate correctly when no popup was displayed. However, when the popup was displayed and the user tried to move it, the openGL scene would rotate rather than correctly transferring focus to the popup and moving that instead.

    Then, even after I fixed the above problem I ran into an additional issue: calling QDialog::show() and QGraphicsProxyWidget::setFocus() messed up the openGL state. The result was that the QGraphicsScene::drawBackround() code produced artifacts/garbage once the proxy popup was opened.

    To fix that problem I added beginNativePainting() and endNativePainting() calls to the drawBackground() definition (which I should have had in place before anyways).

    Qt Code:
    1. void MyGraphicsScene::drawBackground(QPainter *painter, const QRectF &)
    2. {
    3. painter->beginNativePainting();
    4. ...
    5. painter->endNativePainting();
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 10
    Last Post: 10th November 2010, 03:12
  2. Problem setting central Widget layout
    By frenk_castle in forum Newbie
    Replies: 2
    Last Post: 26th September 2009, 16:43
  3. Adding QGraphicsProxyWidget items into QGraphicsScene
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2008, 06:33
  4. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 06:09
  5. Setting focus on Canvas
    By Kapil in forum Qt Programming
    Replies: 10
    Last Post: 17th May 2006, 12:55

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.