1

Topic: The job of layout Rect'a for Qmenu - a C ++ Qt

It is banal there is button QToolButton and QMenu, anchor the button to the menu that on a clique it was caused: connect (MyToolButton, SIGNAL (clicked (bool)), MyToolButton, SLOT (showMenu()); and further: QMenu* menu = new QMenu; MyToolButton-> setMenu (menu); MyToolButton-> setStyleSheet ("QToolButton:: menu-indicator {image: none;}"); QToolButton* tb = new QToolButton; QHBoxLayout* hb = new QHBoxLayout; hb-> addWidget (tb); menu-> setLayout (hb); int x, y, w, h; MyWidget-> geometry ().getRect (&x,&y,&w,&h);// on which button MyToolButton QRect rect (x, y, w, h is allocated); menu-> setGeometry (rect); but menu layout does not change at all, I set  even 0.0 Result same. A question: What it is necessary to make to change a location of the appearing menu on a clique?

2

Re: The job of layout Rect'a for Qmenu - a C ++ Qt

Hello, TOPAZ23, you wrote: TOP> It is banal there is button QToolButton and QMenu, anchor the button to the menu that on a clique it was caused: TOP> TOP> connect (MyToolButton, SIGNAL (clicked (bool)), MyToolButton, SLOT (showMenu ())); TOP> TOP> and further: TOP> TOP> QMenu* menu = new QMenu; TOP> MyToolButton-> setMenu (menu); TOP> MyToolButton-> setStyleSheet ("QToolButton:: menu-indicator {image: none;} "); TOP> QToolButton* tb = new QToolButton; TOP> QHBoxLayout* hb = new QHBoxLayout; hb->> addWidget (tb); menu->> setLayout (hb); TOP> int x, y, w, h; TOP> MyWidget-> geometry ().getRect (&x,&y,&w,&h);// on which button MyToolButton TOP> QRect rect (x, y, w, h is allocated); TOP> menu-> setGeometry (rect); TOP> TOP> but menu layout does not change at all, I set  even 0.0 Result same. TOP> a question: What it is necessary to make to change a location of the appearing menu on a clique? Instead of showMenu (), manually cause menu-> exec (...), transferring the necessary coordinates. connect (MyToolButton, (void (QToolButton:: *) (void)) (&QToolButton::clicked), [MyWidget, menu] () {menu-> exec (MyWidget-> mapToGlobal (MyWidget-> rect ().center ()));});