PDA

View Full Version : Disable the QToolBar when the QMenuBar gets disabled?



dobedidoo
19th January 2010, 09:10
Hi,
In my application (in the QMainWindow) I use a QMenuBar and a QToolBar. When other widgets than my QMainWindow (typically QDialog:s, even such that are not Modal) are "focused", in general the QMenuBar is automatically "disabled". The QMenuBar gets enabled again when the other widget is closed, or when "activating"/"focusing" the QMainWindow. This is some kind of default behaviour of the QMenuBar in my QMainWindow, and I would very much like my QToolBar to behave in the same way - to "disable" it when for example a QDialog opens (and are focused), to prevent the user from thinking that he/she can use the ToolButtons all the time.

I've tried changing the QMainWindow:s 'focusInEvent' and 'focusOutEvent', but I did not succeed in "capturing" the correct behaviour. The QMenuBar:s enable/disable state does not seem to be precisely correlated to the focus state od the QMainWindow. Or did I just not succed?

In other word - is there a way of having the QToolBar:s enabled/disabled state "following" the enabled/disabled state of the QMenuBar???

nikhilqt
19th January 2010, 12:42
Go thru,

qwidget::setFocusPolicy (http://doc.trolltech.com/4.6/qwidget.html#focusPolicy-prop)

qwidget::setFocus (http://doc.trolltech.com/4.6/qwidget.html#setFocus)


If you want user not to use any toolbuttons, just disable the toolbar if focus is out of the mainwindow. If you want to handle QToolBar's event in mainwindow, Try using http://doc.trolltech.com/4.6/qobject.html#installEventFilter

dobedidoo
19th January 2010, 13:51
Well, the thing is that I'd already tried using the focusInEvent()/focusOutEvent(), but it seems that the QMainWindow does not actually "focusOut" when I, for example, open a QDialog, and so it does not "focusIn" if I close the dialog.

Could there be other ways of solving this?