Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I make my app appear on the secondary monitor?
Forum Updated to NodeBB v4.3 + New Features

How do I make my app appear on the secondary monitor?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt creatorvisual studiomulti monitor
4 Posts 3 Posters 6.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SprezzaturaS Offline
    SprezzaturaS Offline
    Sprezzatura
    wrote on last edited by
    #1

    I am able to successfully override the beginning size and position of the screen, but not which monitor it appears on. Using Visual Studio, Windows 10, Qt 5.13.

    Here's what I have tried (note screen is set to '1', the secondary monitor)

    In the following case, 'qwin' is NULL, can't invoke setScreen()

    MainWindow::MainWindow()	// constructor of main window; 'MainWindow' is a QMainWindow which inherits from QWidget
    {	// 'theApp' is QApplication *
    	QWindow *qwin = windowHandle();
    	if(qwin)	// 'qwin' is NULL, even though the parent is a QMainWindow which inherits from QWidget
    	{	QList<QScreen *> qscreens = theApp->screens();
    		if(screen < qscreens.size())
    			qwin->setScreen(qscreens[screen]);
    	}
    }
    

    In the following case, 'qwin' is NULL, can't invoke setScreen()

    MainWindow::MainWindow()
    {	QWidget *topWidg = window();
    	if(topWidg)		// not NULL
    	{	QWindow *qwin = topWidg->windowHandle();
    		if(qwin)	// NULL
    		{	QList<QScreen *> qscreens = theApp->screens();
    			if(screen < qscreens.size())
    				qwin->setScreen(qscreens[screen]);
    		}
    	}
    }
    

    In the following case, 'qwin' is NOT NULL, but setScreen() does not take effect,
    the app stays on primary screen (0) instead of appearing on secondary screen (1)

    MainWindow::MainWindow()
    {	QDesktopWidget qdskWidg = theApp->desktop(); // 'theApp' is QApplication 
    	if(qdskWidg)	// not NULL
    	{	QWindow *qwin = qdskWidg->windowHandle();
    		if(qwin)	// not NULL
    		{	QList<QScreen *> qscreens = theApp->screens();
    			if(screen < qscreens.size())
    				qwin->setScreen(qscreens[screen]);	// stays on primary (0) even though 'screen' is 1
    		}
    	}
    }
    

    Does anyone have a simple "Hello World" example that explicitly positions itself on the second monitor?

    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From the top of my head, I would get the center of the screen geometry and apply that to the widget.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      SprezzaturaS 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        From the top of my head, I would get the center of the screen geometry and apply that to the widget.

        SprezzaturaS Offline
        SprezzaturaS Offline
        Sprezzatura
        wrote on last edited by
        #3

        @SGaist You mean like this:

        QDesktopWidget *desktopWidget = qApp->desktop();
        QRect secondScreenGeometry = desktopWidget->screenGeometry(1);
        myWidget->move(secondScreenGeometry.center());
        

        Does not work.

        1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Hi, try:

          myWidget->setGeometry(secondScreenGeometry);
          
          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved