How to create a child widget floating
-
Hi all
I would to create a child windget able to "ignore" any layout and that can be showed in any part of the main window (on top of other widgets) using main window coordinates. I know is possible to make such result by creating a widget without a parent but in this case the widget became like an indipendent window and use global screen coordinates. On the contrary I would my floating widget to be child of main window with the consequence if you move the main window this floating widget will be moved as well (basically like a MDI windows). Currently I didn't find a way for this problem yet, have you some suggestion about?
Thank you
-
You can implement the mouseMoveEvent and use the maptoParent or mapToGlobal parameter.
See the following code snippet. I have created my own label and set the parent as Widget. There is no layout. When I move the mouse, mylabel follows the mouse cursor.
@void MyLabel::mouseMoveEvent(QMouseEvent *ev){
qDebug() << " MY pos = "<< ev->pos();
QPoint p1 = ev->pos();
QPoint p = mapToParent(p1);
this->setGeometry(p.x(),p.y(),this->width(),this->height());
}@ -
ahhh....It is not trick. This is how it works. There is no ready made stuff. Check for dockwidgets if something fits your requirement.