Dropdown tool from toolbar...
-
I'm using QtQuick to attempt to somewhat recreate a winform application. One thing that I am trying to mimic is that from the toolbar, I can click on a toolbar button and it drops down a window containing some controls - in my particular case, it's dropping down a volume control slider - and it's behavior works basically the same as a menu - if I click on the toolbutton, the control appears below the button, if I click anywhere outside the window, the window disappears, and if I click on the button, the window disappears (ie. the button will toggle the control display).
I'm a little stuck on how to proceed, currently I have a popup window and I launch it from the button. It works as expected EXCEPT for re-pressing on the button. If I press the button while the popup window is visible, the window loses active status first and hides, then the button receives the click which sees that the popup is hidden and redisplays it - so it quickly flashes the control off and on. Any way to get the expected behavior so that pressing the button while the control (dropdown) is visible can force the control to hide, or to somehow set the button / mousearea into some state so that that first click gets ignored (so the control loses active / focus, but the button doesn't try to re-open it).
@
ToolButton {
id: volumeButton
...
onClicked: {
if (!volumePopup.visible)
{
var loc = volumeButton.mapToItem(null, 0, 0);
volumePopup.x = mainWindow.x + loc.x
volumePopup.y = mainWindow.y + loc.y + volumeButton.height;
volumePopup.visible = true;
volumePopup.requestActivate();
}
}
}Window {
id: volumePopup
flags: Qt.Popup
visible: false
...
onActiveChanged: if (!active) volumePopup.visible = false;
}
@