[Qt-interest] How to make a QPushButton inside a QGraphicsView lose focus ?
Malyushytsky, Alex
alex at wai.com
Mon May 10 21:33:43 CEST 2010
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 )
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);
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.
Hope it helps.
Alex
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Aaron Lewis
Sent: Monday, May 10, 2010 5:39 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] How to make a QPushButton inside a QGraphicsView lose focus ?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Inside a QGraphicsView , i have a Scene and a Button.
I first created a QGraphicsScene and use setScene() function in
QGraphicsView , then created QPushButton.
===========================================================
Sample Code:
scene = new Scene(); // Scene inherits QGraphicsScene
setScene(scene);
QPushButton *leaveButton = new QPushButton(this); // use QGraphicsView
as parent
scene->addItem(leaveButton);
============================================================
And now my QPushButton takes focus , how should i make my scene get
focus now ?
- ------------------------
| View |
|---------- -------- |
|| Button | | Scene | |
|---------- --------- |
- ------------------------
Appreciate any of you help ;-)
Thanks.
- --
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/
iEYEARECAAYFAkvn/m4ACgkQvf41sEptMqAE9wCfRcssMW2sbpBwdsd4AlztJhoz
hBEAoNJkmaPHd31AJnkzPLbMeaufnt5s
=mYjz
-----END PGP SIGNATURE-----
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”
“Please consider our environment before printing this email.”
More information about the Qt-interest-old
mailing list