Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How to avoid this?

like image 330
Thomas Ayoub Avatar asked Nov 06 '13 16:11

Thomas Ayoub


People also ask

How to full screen Qt?

Use double click to reveal the element on the full screen. Use {Esc} to return to the layout.

How do I maximize a window in Qt?

Press Ctrl+F and type "maximized"

Can you make a widget full screen?

This article will show you step by step how to make a widget full screen. By default, the widget pop-up only takes up part of the screen. It is now possible to make widgets full screen. Go to the "Settings" tab > Click on "Widgets" > Select "full screen" in the pop up dimension.


2 Answers

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

QTimer::singleShot(0, this, SLOT(showFullScreen())); 
like image 200
Martin Delille Avatar answered Oct 06 '22 07:10

Martin Delille


use the following if you want to have the app open as maximized window:

Mainwindow w; w.setWindowState(Qt::WindowMaximized); w.show(); 

use the following if you want to have the app open as fullscreen window:

Mainwindow w; w.setWindowState(Qt::WindowFullScreen); w.show(); 
like image 29
Zhang Tianbao Avatar answered Oct 06 '22 05:10

Zhang Tianbao