Unsolved Does Qt support Mac-style pop-out widgets?
-
I am not a Mac developer does anyone know what these kind of controls are called:
Here this pops out from a button and is able to extend beyond the parent/main window, but if you click outside the popout widget it automatically disappears. I'm not familiar with this kind of toolbar widget in WinAPI and as we're developing a cross-platform application based on an existing Mac application, I'd like to know if Qt can provide something similar/use these native widgets in a cross-platform way?
Thanks.
-
OK so in Mac speak these are "popovers" https://developer.apple.com/design/human-interface-guidelines/macos/windows-and-views/popovers/
Does Qt support them, and if so what is the Windows equivalent? If not, what is the closest cross-platform alternative - it's just neat they disappear when you click away.
-
Hi
Qt do not have such control/widget. (as far as i know)
For a cross platform solution, i think you would have to make a custom widget.
Technically its similar to a QComboBox that also allows to go out side parents area and
will close on click outside. It uses a event filter to be able to close if click outside.so you could go dig around in its code
https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qcombobox.cpp.htmlto be inspired.
Basically it would be a frame less floating window and some eventfilter to
obtain a similar effect. -
You can make your own custom widget based on Qt::PopUp window flag.
Here my own widget constructor:static const int ArrowSize=13; PopupWindow::PopupWindow(QWidget *parent) : QWidget(parent) { setWindowFlags(Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint|Qt::Popup); setAttribute(Qt::WA_TranslucentBackground); setContentsMargins(ArrowSize+1,ArrowSize+1,ArrowSize+1,ArrowSize+1); oContentWidget=new ContentWidget(this); oContentWidget->setMinimumSize(QSize(100,100)); oContentWidget->move(ArrowSize+1,ArrowSize+1); oContentWidget->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); // widget shadow pShadowEffect = new QGraphicsDropShadowEffect(); pShadowEffect->setBlurRadius(18); pShadowEffect->setColor(ShadowColor[ShadowColor_Active]); pShadowEffect->setOffset(QPoint(1,4)); setGraphicsEffect(pShadowEffect); }
You need to define an AnchorPoint and a AnchorWidget to position the popup correctly. For ex:
void PopupWindow::showWithAnchor(QWidget* anchorWidget, Qt::AnchorPoint anchorPt) { ... }
Some work required ;)
-
Thanks, this is most helpful. It seems this is a Mac-native control so it makes sense Qt doesn't support directly.
-