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. setGeometry vs Resize+Move
Forum Updated to NodeBB v4.3 + New Features

setGeometry vs Resize+Move

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

    Hi,
    I have a dialog, that I need to resize 2 or 3 times. The dialog should always be centered, so I use resize , and move:

    // within the dialog class (a slot)
    this->move(x() - ((newWidth-width())/2) , y() - ((newHeight-height())/2));
    this->resize(newWidth, newHeight);
    

    This code works, but when I use setGeometry with the same parameters it won't work. I need setGeometry to work because I want to animate the resizing.
    That's it. Thanks for your help.

    "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      in what way does setGeometry not work ?
      http://doc.qt.io/qt-5/qwidget.html#geometry-prop
      This is relative to parent coordinates
      However, Move docs says
      "If the widget is a window, the position is that of the widget on the desktop, including its frame."
      And since you have a dialog, it might apply.

      Anyway, you can center a dialog to center of screen with

      #include <QStyle>
      #include <QDesktopWidget>
      
      window->setGeometry(
          QStyle::alignedRect(
              Qt::LeftToRight,
              Qt::AlignCenter,
              window->size(),
              qApp->desktop()->availableGeometry()
          )
      );
      
      1 Reply Last reply
      2
      • SamurayHS Offline
        SamurayHS Offline
        SamurayH
        wrote on last edited by
        #3

        Solved. Thanks so much @mrjj.

        "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

        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