Hi Guys,
What I'm trying to implement is custom PopUp Menu for custom PushButton placed in TollBar.
PopUp menu is implemented via QWidget. For now it is simple black widget, in the end it should contain a number of PushButtons.
#ifndef POPUPMENU_H
#define POPUPMENU_H
#include <QWidget>
#include <QPalette>
namespace Ui {
class PopUpMenu;
}
{
Q_OBJECT
public:
explicit PopUpMenu
(QWidget *parent
);
~PopUpMenu();
private:
Ui::PopUpMenu *ui;
std::unique_ptr<QPalette> pal;
};
#endif // POPUPMENU_H
PopUpMenu
::PopUpMenu(QWidget *parent
) : ui(new Ui::PopUpMenu)
{
ui->setupUi(this);
this->setGeometry(parent->x(), parent->y() + parent.height(), parent->width() * 3, parent->height());
//this->setGeometry(parent->rect().bottomLeft().x(), parent->rect().bottomLeft().y(), parent->width() * 3, parent->height());
pal = std::make_unique<QPalette>();
this->setPalette(*pal);
this->setWindowFlags(Qt::Popup);
}
PopUpMenu::~PopUpMenu()
{
delete ui;
}
#ifndef POPUPMENU_H
#define POPUPMENU_H
#include <QWidget>
#include <QPalette>
namespace Ui {
class PopUpMenu;
}
class PopUpMenu : public QWidget
{
Q_OBJECT
public:
explicit PopUpMenu(QWidget *parent);
~PopUpMenu();
private:
Ui::PopUpMenu *ui;
std::unique_ptr<QPalette> pal;
};
#endif // POPUPMENU_H
PopUpMenu::PopUpMenu(QWidget *parent) :
QWidget(parent),
ui(new Ui::PopUpMenu)
{
ui->setupUi(this);
this->setGeometry(parent->x(), parent->y() + parent.height(), parent->width() * 3, parent->height());
//this->setGeometry(parent->rect().bottomLeft().x(), parent->rect().bottomLeft().y(), parent->width() * 3, parent->height());
pal = std::make_unique<QPalette>();
pal->setColor(QPalette::Window, QColor((Qt::black)));//testing
this->setPalette(*pal);
this->setWindowFlags(Qt::Popup);
}
PopUpMenu::~PopUpMenu()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
In my button I simply create an instance of PopUpMenu and via reimplemented QWidget::enterEvent() show it buy invoking menu.show().
the line this->setGeometry(parent->x(), parent->y() + parent.height(), parent->width() * 3, parent->height());
works fine for size, but places the PopUp widget in respect of global display coordinates, that is, in top left corner of display, but not an application window.
Tried mapFrom(To) functions - no luck.
Need advise how to set the coordinates related to QWidget not to display.
Thank you
Bookmarks