PDA

View Full Version : Having trouble maximizing my window - It resizes too large



ComServant
4th February 2012, 20:08
I want my window to have four different modes:
- Fullscreen
- Maximized without a border (like fullscreen, but the taskbar is still visible)
- Maximized
- Windowed (non-resizable)

Windowed works fine, and maximized without a border works fine, but regular maximized isn't working.

Regular plain-vanilla Maximized is filling up the entire screen including under the taskbar.

Here's a screenshot showing what I mean:

7360
(editted, to cut down on resolution by cutting out blank space)

I've tried multiple different ways of setting maximized, including:

QWidget::setWindowFlags(Qt::Window);
QWidget::setWindowState(Qt::WindowActive, Qt::Maximized);

I also tried manually re-sizing it, and I tried using QWidget::showMaximized().

Here's my current code:

void MainWindow::_recalculateWindowSize()
{
//Undo any previous minimums and maximums.
QWidget::setMinimumSize(0, 0);
QWidget::setMaximumSize(1000000, 1000000);

//Choose what settings to use, depending on WindowMode.
if(this->windowMode == Engine::WindowMode::Fullscreen)
{
QWidget::setWindowFlags(Qt::Window);
QWidget::resize( qApp->desktop()->size() );
QWidget::showFullScreen();
}
else if(this->windowMode == Engine::WindowMode::Multitask)
{
QWidget::setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

QRect desktopGeometry = qApp->desktop()->availableGeometry();
QWidget::resize(desktopGeometry.size());
QWidget::move(desktopGeometry.x(), desktopGeometry.y());

QWidget::setWindowState(Qt::WindowActive); //Qt::Maximized
}
else if(this->windowMode == Engine::WindowMode::Maximized)
{
QWidget::setWindowFlags(Qt::Window);

//QWidget::setGeometry(qApp->desktop()->availableGeometry());
QWidget::showMaximized();
}
else //Engine::WindowMode::Windowed
{
WindowSize windowSize = this->_calculateWindowSizeWithEditor(this->requestedWindowSize);

QWidget::setWindowFlags(Qt::Window | Qt::WindowMinMaxButtonsHint);

QWidget::showNormal();
QWidget::resize(windowSize.ToQSize());
//QWidget::setFixedSize(windowSize.ToQSize());

QWidget::move(50, 50); //Temp, haven't cent
}

QWidget::show(); //Have to 'show()' to apply the new setWindowState() state.
QWidget::grabKeyboard(); //Just incase we accidentally lost focus during the transition.
}

MainWindow private inherits QWidget (but brings QObject into the public interface), and has no parent.
(Note: It's not a QMainWindow, if that matters. I have no QMainWindow, just a parentless QWidget)

Any ideas what I'm doing wrong?

blaquee
5th February 2012, 15:41
Hello, quick question concerning the screenshot, is the windows taskbar set to auto hide? sometimes when thats the case the full screen is calculated as the space underneath the taskbar.

ComServant
5th February 2012, 17:44
No, it's not set to autohide. If it was set to autohide, I'd like it to fill that taskbar space, but it's not set to that.

Thanks for the good question, though. =)