When you save a file on a Mac, a panel kinda descends down from the top bar in a really cool way. I want to create a class that does a similar thing using the Qt framework. There are a number of things that I’m confused about:
-
When the panel descends, input to the parent window should be blocked. This is easy with QDialog as it has the setModal() method, however – QDialogs, by default pop-out. I’m not sure how to get around this.
-
In a QMainProject, there is a QMenua new instance of the DescendingPanel class is created. How would you do that, supposing there are other widgets below the menubar. The DescendingPanel should appear above them.
I would really appreciate any help with this.
EDIT
I had an idea that instead of pegging the dialog under the menubar, just make it appear under there and remove the window frame. That way, it would give an illusion that it popped out from under there. Ofcourse, Move events would also have to be handled so that the Dialog is always under the menubar but that’s for later. Here’s the code I used to get the DescendingDialog to appear under the menubar.
class DescendingDialog : public QWidget
{
QMainWindow* Window;
QWidget* Menu;
QPoint GlobalLocationOfMenu;
int DialogWidth;
int DialogHeight;
int X()
{
int XDistanceOfPanel = GlobalLocationOfMenu.x() + ((Menu->width()/2) - (this->DialogWidth/2));
//GlobalLocationOfMenu.x() returns 0;
return XDistanceOfPanel;
}
int Y()
{
int YDistanceOfPanel = GlobalLocationOfMenu.y()+Menu->height();
//GlobalLocationOfMenu.y() returns 0;
return YDistanceOfPanel;
}
void SetGeometry()
{
this->setGeometry(this->X(),this->Y(),this->DialogWidth,this->DialogHeight);
}
public:
DescendingDialog(QMainWindow* Window,int DialogWidth,int DialogHeight):QWidget(NULL)
{
this->Window = Window;
this->Menu = this->Window->menuWidget();
this->DialogWidth = DialogWidth;
this->DialogHeight = DialogHeight;
QPoint RelativeLocationOfMenu = this->Menu->pos();
this->GlobalLocationOfMenu = QWidget::mapToGlobal(RelativeLocationOfMenu);
this->SetGeometry();
}
};
It didn’t work because the GlobalLocationOfMenu.x() and .y() returned 0 so the dialog doesn’t appear where I want it to.
You can let a dialog “slide in” by using a function similar to that:
The
dialogargument shall point to a (hidden/not visible) QDialog instance with one single child widget, that contains all other widgets that belong to the dialog.The
geometryEndargument shall specify position and size ofdialogafter it has appeared (relative to it’s parent widget).The result looks like this.