PDA

View Full Version : Do the layout class can receive the mouse event?



tszzp
22nd December 2009, 10:09
Now I convert the WPF program to Qt, because the project need cross-platform. In WPF program, the layout(Panel, Grid, StackPanel...) is also control, so it also can receive the mouse event. but in Qt, the layout(QLayout, QGridLayout...) isn't derived by QWidget, so i want to know if the layout class can receive the mouse event. I write a simple sample, derived a class from QVBoxLayout, find I can't receive the mousePressEvent when I press the mouse in the layout. thanks.

high_flyer
22nd December 2009, 10:37
A layout is not a widget, it not a visible object, so it makes no sense for it to receive any input.
Since a QLayout is a QObject, you could use it as an event filter for another widget, but the question is, what would you do with the event then?

tszzp
23rd December 2009, 04:27
Ok, let me explain my question in detail.for example, QVBoxLayout include several controls(such as button, listwidget...), when user press the mouse then move the mouse, the all controls in the QVBoxLayout will move, this is the effect I want to implement. In WPF, the layout is also the control, so it is easy to do the effect. how to do the same effect in Qt? thanks.

wysota
23rd December 2009, 09:07
Maybe you should just use QScrollArea?

Please notice that when porting an application to a different system/framework you shouldn't try to mimic the original code as much as possible. There are differences between frameworks - different approaches and concepts. Instead you should try to grasp the spirit of the framework you are using and implement your code instead of traslating it.