MOC89 MOC89 - 1 year ago 98
C++ Question

Show Mainwindow in the right of the screen (Qt 5.1.0)

I want to show my mainwindow in the right side of the screen.

I use this code :

QRect r = this->frameGeometry();

And I receive this error :

error: cannot call member function 'const QRect QDesktopWidget::availableGeometry(int) const' without object

If I use 1024 instead
it works... But I don't want to initialize it staticly...

How can I dynamically reposition the window for different screen sizes?

Answer Source

QDesktopWidget::availableGeometry is not a static function. You can use QApplication::desktop() function to get a QDesktopWidget object:

QRect r  = this->frameGeometry();

You will have to put something else in the moveRight() function. You can't put a QRect there. Maybe what you want to do is:

QRect r = QApplication::desktop()->availableGeometry();
this->resize(r.width(), r.height());

Or if you don't want to resize your window:

QRect r = QApplication::desktop()->availableGeometry();
QRect main_rect = this->geometry();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download