[Qt-interest] Off-screen render with QGraphicsView; focus issues?
Girish Ramakrishnan
girish at forwardbias.in
Tue Dec 15 04:45:04 CET 2009
Glad it helped :-)
Girish
Penn Taylor wrote:
> Girish,
>
> Thanks! Your solution works very well. In playing around with my app
> to understand which pieces do the magic, I found that the two things
> that were necessary were the QEvent::WindowActivate on the scene and
> the use of qt_sendSpontaneousEvent to gain access to
> QCoreApplication::sendSpontaneousEvent.
>
> I found that items #2 and #3 in your solution below weren't required
> (by my app at least) and the QEvent::ActivationChange on the scene
> wasn't needed. You might try commenting those parts out of your app
> and see if it still functions. It might save you a few lines of code
> and a few function calls.
>
> Thanks again, Penn taylor
>
> Girish Ramakrishnan wrote:
>> Hi Penn,
>>
>> Indeed, I have been facing the exact same problems as yours (very
>> similar use case too). 4.6 QGV seems to have changed lots of it's
>> existing behavior.
>>
>> After lots of QGV code grokking, here's how I solved my problems:
>>
>> 0. Things work differently when you have a (hidden) QGraphicsView
>> and when you have _no_ view (i.e just a scene). When you are using
>> a hidden QGraphicsView, the code seems to rely on the screen pos to
>> locate items under the cursor.
>>
>> 1. Send QEvent::WindowActivate and QEvent::ActivationChange to the
>> scene to make it believe that the view is now activated.
>>
>> 2. Call QGraphicsItem::setActive(true) for your proxy widget to
>> make the scene understand the item is now active.
>>
>> 3. Call QGraphicsScene::setFocusItem() to make the scene understand
>> that the item now gets keyboard focus.
>>
>> 4. The focus code seems to rely on events being spontaneous. This
>> was the toughest part to fix because
>> QCoreApplication::sendSpontaneousEvent is internal. But I found a
>> super hack :-) qt_sendSpontaneousEvent is a non-exported function
>> which is a friend of QCoreApplication. This means that you can add
>> your own qt_sendSpontaneousEvent and call
>> QCoreApplication::sendSpontaneousEvent. I could not figure a way to
>> make mouse handling work correctly without this hack.
>>
>> There is some hard to understand but working code at
>> http://git.forwardbias.in/?p=hacks/qtwebkitgl.git;a=summary
>> (gvcapture branch). It captures the contents of a QGraphicsWebView.
>> On a page that requries http auth, a dialog is displayed which is
>> where I faced the issues above.
>>
>> Girish
>>
More information about the Qt-interest-old
mailing list