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. Window widget not moving with move()

Window widget not moving with move()

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.8k 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.
  • Xena_oX Offline
    Xena_oX Offline
    Xena_o
    wrote on last edited by Xena_o
    #1

    hello

    i am trying to move a window with move() inside a MDIarea but that is not working, here is the code :

    wCon = new myWindow(this);
    wCon->setAttribute(Qt::WA_DeleteOnClose);
    ui->mdiArea->addSubWindow(wCon);
    wCon->setFixedSize(200,200);
    int x, y;
        x = (this->width() - wCon->width())/2;
        y = (this->height() - wCon->height())/2;
    wCon->move(x,y);
    wCon->show();
    // this = mainWindow that contains the MDI
    // myWindow = QWidget class
    // also tried : wCon->move(wCon->rect().center());
    

    the new window stays at top left of the MDIarea and does not move to the new location (center of MDI area).

    Any idea why ?

    Pl45m4P 1 Reply Last reply
    0
    • Xena_oX Xena_o

      hello

      i am trying to move a window with move() inside a MDIarea but that is not working, here is the code :

      wCon = new myWindow(this);
      wCon->setAttribute(Qt::WA_DeleteOnClose);
      ui->mdiArea->addSubWindow(wCon);
      wCon->setFixedSize(200,200);
      int x, y;
          x = (this->width() - wCon->width())/2;
          y = (this->height() - wCon->height())/2;
      wCon->move(x,y);
      wCon->show();
      // this = mainWindow that contains the MDI
      // myWindow = QWidget class
      // also tried : wCon->move(wCon->rect().center());
      

      the new window stays at top left of the MDIarea and does not move to the new location (center of MDI area).

      Any idea why ?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      Hi,

      @Xena_o said in Window widget not moving with move():

      wCon->move(x,y);

      you have to move your widget as QMdiSubWindow not as QWidget (otherwise it moves the widget content inside your MdiWindow and not the whole MdiWindow in your MdiArea.)

      Try mdiArea->activeSubWindow()->move(x, y);
      (or currentSubWindow())

      • https://doc.qt.io/qt-5/qmdiarea.html#currentSubWindow

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      Xena_oX 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        Hi,

        @Xena_o said in Window widget not moving with move():

        wCon->move(x,y);

        you have to move your widget as QMdiSubWindow not as QWidget (otherwise it moves the widget content inside your MdiWindow and not the whole MdiWindow in your MdiArea.)

        Try mdiArea->activeSubWindow()->move(x, y);
        (or currentSubWindow())

        • https://doc.qt.io/qt-5/qmdiarea.html#currentSubWindow
        Xena_oX Offline
        Xena_oX Offline
        Xena_o
        wrote on last edited by Xena_o
        #3

        @Pl45m4 thank you !

        with your help i could figure out how the code should be:

        wCon = new myWindow(this);
        
            QMdiSubWindow *cw = new QMdiSubWindow;
            cw->setWidget(wCon);
        
            //destroy window on close
            cw->setAttribute(Qt::WA_DeleteOnClose);
        
            //add window to MDI area
             ui->mdiArea->addSubWindow(cw);
        
            //put window in middle of MDI
            cw->move(wCon->rect().center());
        
            //show the window
            cw->show();
        

        this code works well ! thanks !

        1 Reply Last reply
        1

        • Login

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