Darkgaze
Darkgaze

Reputation: 2573

Position pop up window over a QWidget in runtime

I know there are answers, but they don´t satisfy my question. It´s not working for me.

I have a simple custom widget called PopUp. It inherits the SmartPanel which is a styled panel and just contains:

setWindowFlags( Qt::Window | Qt::FramelessWindowHint );
setAttribute(Qt::WA_QuitOnClose, true);
setAttribute( Qt::WA_TranslucentBackground );

It shows a window that should appear over a button you push that pops it up or closes. if you enter and get out of it, it closes by itself.

I tried:

A) Making it child of the button, so where the button moves, it moves. Obviously should work. Well. Doesn´t work at all... It always stays on 0,0 on the top left corner of the window. I even move the window , the button moves and the popup stays the same... even being it´s child!.

SmartPopUp::SmartPopUp( QWidget *parent): SmartPanel(parent)
{
   setContentsMargins(30,10,20,20);
   hide();
   QVBoxLayout* lyt = new QVBoxLayout();
   setLayout(lyt);
 }

B) Save inside a link to the assoc. widget, to get its position. Getting position of the widget doesn´t work properly. Don´t know why...

SmartPopUp::SmartPopUp( QWidget* associatedWidget, QWidget *parent): SmartPanel(parent)
{
  associatedWidget_ = associatedWidget;
  setContentsMargins(30,10,20,20);
  hide();

  QVBoxLayout* lyt = new QVBoxLayout();
  setLayout(lyt);
}

How to make it move together with the changing position of the button?

Upvotes: 0

Views: 2453

Answers (1)

Amit Tomar
Amit Tomar

Reputation: 4858

  1. Make a topWidget.

  2. Make SmartPoUp and SmartPanel as children for this parent.

  3. Call raise() for SmartPoUp

  4. Reimplement moveEvent for SmartPanel and move your SmartPopup as well according to new position of SmartPanel.

Upvotes: 0

Related Questions