PDA

View Full Version : How to hide the mainToolBar automatically?



drunknight
30th November 2013, 08:07
I am new to Qt,and i am doing a project now.There is a requirement that toolBar could be hided automatically,and when cursor is near the topToolBarArea toolBar show itself.I am afraid to say that it's really not a difficult feature or function,but i really need help here!

anda_skoa
30th November 2013, 12:06
You will need to implement some mouse event handling, for example in your main window class.

You initially hide the toolbar and show it when the mouse moves into the target area.

Cheers,
_

drunknight
3rd December 2013, 12:59
Is there anyway you can give me a code example,please?

zgulser
3rd December 2013, 13:17
Something like;

QMainWindow::menuBar()->hide();

You can do it from the designer as well.

drunknight
3rd December 2013, 13:54
What I really need is to show the ToolBar when the mouse cursor moves to some specific area.Would you give me some suggestions?

zgulser
3rd December 2013, 14:06
Oh I see...To do so you need to handle mouse events in the regarding ui's controller class. You can do it in various ways.

1. You can reimplement QWdiget::mouseMoveEvent(QmouseEvent* e).

2. You can use eventFilter() method along with installEventfilter()

You can get the current mouse position from both ways above and compare the position if it's on your widget. Then you can show/hide the toolbar.

drunknight
3rd December 2013, 14:20
Thank you.I will try it in both way: )

anda_skoa
3rd December 2013, 14:30
1) enable mouse tracking, see QWidget::setMouseTracking()
2) overwrite mouseMoveEvent()
3) check QMouseEvent::pos()

Cheers,
_