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.

Qt Code:
  1. #ifndef POPUPMENU_H
  2. #define POPUPMENU_H
  3.  
  4. #include <QWidget>
  5. #include <QPalette>
  6.  
  7.  
  8. namespace Ui {
  9. class PopUpMenu;
  10. }
  11.  
  12. class PopUpMenu : public QWidget
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. explicit PopUpMenu(QWidget *parent);
  18. ~PopUpMenu();
  19. private:
  20. Ui::PopUpMenu *ui;
  21. std::unique_ptr<QPalette> pal;
  22. };
  23.  
  24. #endif // POPUPMENU_H
  25.  
  26. PopUpMenu::PopUpMenu(QWidget *parent) :
  27. QWidget(parent),
  28. ui(new Ui::PopUpMenu)
  29. {
  30. ui->setupUi(this);
  31.  
  32. this->setGeometry(parent->x(), parent->y() + parent.height(), parent->width() * 3, parent->height());
  33. //this->setGeometry(parent->rect().bottomLeft().x(), parent->rect().bottomLeft().y(), parent->width() * 3, parent->height());
  34. pal = std::make_unique<QPalette>();
  35. pal->setColor(QPalette::Window, QColor((Qt::black)));//testing
  36. this->setPalette(*pal);
  37. this->setWindowFlags(Qt::Popup);
  38. }
  39.  
  40. PopUpMenu::~PopUpMenu()
  41. {
  42. delete ui;
  43. }
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