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:
screenshot.png
(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);
QWidget::setWindowFlags(Qt::Window);
QWidget::setWindowState(Qt::WindowActive, Qt::Maximized);
To copy to clipboard, switch view to plain text mode
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::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
() );
}
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());
}
else //Engine::WindowMode::Windowed
{
WindowSize windowSize = this->_calculateWindowSizeWithEditor(this->requestedWindowSize);
QWidget::setWindowFlags(Qt
::Window | Qt
::WindowMinMaxButtonsHint);
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. }
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.
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks