Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Moving widgets
Forum Updated to NodeBB v4.3 + New Features

Moving widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 291 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • krzysieklfcK Offline
    krzysieklfcK Offline
    krzysieklfc
    wrote on last edited by krzysieklfc
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      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.

      I light my way forward with the fires of all the bridges I've burned behind me.

      1 Reply Last reply
      1
      • krzysieklfcK krzysieklfc

        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?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @krzysieklfc said in Moving widgets:

        newPos -= oldPos

        Why do you have an assignment here?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved