qt-interest@trolltech.com
[Top] [All Lists]

[Qt-interest] [SOLVED] Re: How to make a QPushButton inside a QGraphicsV

Subject: [Qt-interest] [SOLVED] Re: How to make a QPushButton inside a QGraphicsView lose focus ?
From: Aaron Lewis
Date: Tue, 11 May 2010 09:43:15 +0800
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/11/2010 03:33 AM, Malyushytsky, Alex wrote:
> It is not clear what you want to do to me so I would try to clarify what is 
> happening in your case in hope it will help you.
> 
>>> And now my QPushButton takes focus , how should i make my scene get focus 
>>> now ?
> The scene already has a focus and the focus item is leaveButton widget.
> 
> Look at QGraphicsScene::setFocus help:
> "void QGraphicsScene::setFocus ( Qt::FocusReason focusReason = 
> Qt::OtherFocusReason )
> Sets focus on the scene by sending a QFocusEvent to the scene, passing 
> focusReason as the reason. If the scene regains focus after having previously 
> lost it while an item had focus, the last focus item will receive focus with 
> focusReason as the reason.
> If the scene already has focus, this function does nothing."
> 
> If you want move focus to another item you can use
> void QGraphicsScene::setFocusItem ( QGraphicsItem * item, Qt::FocusReason 
> focusReason = Qt::OtherFocusReason )

Cuz my parent Widget is QGraphicsView based , so i'd try with this later
if possible.

> 
> If you don't want leaveButton have focus ever, use
> setFocusPolicy ( Qt::FocusPolicy policy ) // Setting Qt::NoFocus on a widget 
> will clear the ItemIsFocusable flag
> 
> QGraphicsProxyWidget * w =  QGraphicsScene::addWidget ( QWidget * widget, 
> Qt::WindowFlags wFlags = 0 )
> scene->addItem(leaveButton);
> 
> 
> Important! At the first glance I would expect compiler error in
>>>      scene->addItem(leaveButton);

It's scene->addWidget(leaveBtn) instead ;-)

> In my Qt version addItem is declared as :
> void QGraphicsScene::addItem ( QGraphicsItem * item )
> leaveButton is instance of QPushButton  and QPushButton is not  derived from 
> QGraphicsItem
> I would expect to see addWidget instead.
> 

Yeah , it's called FocusPolicy , i tried to setFocusPolicy(Qt::NoFocus)
on QPushButton and it works.

Thanks Alex.


- -- 
Best Regards,
Aaron Lewis - PGP: 0x4A6D32A0
FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
irc: A4r0n on freenode
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkvotjMACgkQvf41sEptMqDx8ACg2m+EywxSrwap42tIo9jNbADU
/jYAn2rDh2+NMXfrE4FMkqqAzA6SNIDE
=U0rZ
-----END PGP SIGNATURE-----
_______________________________________________
Qt-interest mailing list
Qt-interest@xxxxxxxxxxxxx
http://lists.trolltech.com/mailman/listinfo/qt-interest

<Prev in Thread] Current Thread [Next in Thread>