Thomas Ayoub Thomas Ayoub - 1 month ago 13
C++ Question

Qt FullScreen on Startup

I want to start an application on fullscreen (MacOS 10.8.x, Qt 5.1.1, C++) depending on the settings:

main.cpp

#include "MainWindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.showFullScreen();

return a.exec();
}


MainWindow.cpp

#include "MainWindow.h"
#include "ui_MainWindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}


MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H


The settings comportment is perfect, works like a charm. But
this->showFullScreen()
does something very ugly :


  1. Display the window in fullscreen

  2. Display the window in normal size in the center

  3. Scale the window to fullscreen



I can provide a video if needed. How to avoid this?

edit :

add the video here, made a better snippet without the settings

Answer

I already faced this problem and a very nice solution was to delay the fullscreen switch by one second (using a QTimer):

QTimer::singleShot(1000, this, SLOT(showFullScreen()));