
Originally Posted by
wysota
This (almost, it eats up the window decoration too) works for me.
It eats the window decoration because the QRect returned by QWidget::frameGeometry() and QWidget::geometry() (for a top-level widget) are relative to the global coordinate system. They must be mapped from global coordinates to the widget's own coordinate system. This is how I made it work:
// map geometries to widget's coordinates
QRect fg
= frameGeometry
();
fg.moveTo(mapFromGlobal(fg.topLeft()));
gm.moveTo(mapFromGlobal(gm.topLeft()));
// include title and frames
// exclude the area inside frames
region -= gm;
// include all children
region += childrenRegion();
// apply mask
setMask(region);
// map geometries to widget's coordinates
QRect fg = frameGeometry();
fg.moveTo(mapFromGlobal(fg.topLeft()));
QRect gm = geometry();
gm.moveTo(mapFromGlobal(gm.topLeft()));
// include title and frames
QRegion region = fg;
// exclude the area inside frames
region -= gm;
// include all children
region += childrenRegion();
// apply mask
setMask(region);
To copy to clipboard, switch view to plain text mode
Bookmarks