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()
Forum Updated to NodeBB v4.3 + New Features

Window widget not moving with move()

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.6k 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.
  • X Offline
    X Offline
    Xena_o
    wrote on 22 Apr 2021, 14:31 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 ?

    P 1 Reply Last reply 22 Apr 2021, 15:21
    0
    • X Xena_o
      22 Apr 2021, 14:31

      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 ?

      P Offline
      P Offline
      Pl45m4
      wrote on 22 Apr 2021, 15:21 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

      X 1 Reply Last reply 22 Apr 2021, 17:40
      1
      • P Pl45m4
        22 Apr 2021, 15:21

        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
        X Offline
        X Offline
        Xena_o
        wrote on 22 Apr 2021, 17:40 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

        1/3

        22 Apr 2021, 14:31

        • Login

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