Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Moving widgets



  • I want to move child popup QDialog in sync with its parent. I did the following:

    void UI::moveEvent(QMoveEvent* event)
    
    {
    	if (notificationDialog) {
    		auto e = dynamic_cast<QMoveEvent*>(event);
    
    		auto oldPos = e->oldPos();
    		auto newPos = e->pos();
    
    		notificationDialog->move(notificationDialog->pos() + (newPos -= oldPos));
    	}
    	
    	return QMainWindow::moveEvent(event);
    }
    

    It sort of works when I move the QMainWindow very gently, but when I move it faster the dialog offsets a bit from the expected position. It's like moveEvent isn't being properly called .

    Does anyone know why is that?



  • I think this is because you are using a relative offset based on new-old values...mouse movements can be greater than one pixel at a time. Perhaps try using absolute positioning logic instead of relative.


  • Lifetime Qt Champion

    @krzysieklfc said in Moving widgets:

    newPos -= oldPos

    Why do you have an assignment here?


Log in to reply