{"id":150,"date":"2014-10-26T01:05:22","date_gmt":"2014-10-26T06:05:22","guid":{"rendered":"http:\/\/eastfist.com\/qt_tutorials\/?p=150"},"modified":"2017-09-03T17:05:41","modified_gmt":"2017-09-03T23:05:41","slug":"how-to-change-screen-resolution-in-windows-using-qt","status":"publish","type":"post","link":"https:\/\/eastfist.com\/qt_tutorials\/how-to-change-screen-resolution-in-windows-using-qt\/","title":{"rendered":"How to change screen resolution in Windows using Qt"},"content":{"rendered":"<p>If you, too, are scouring the Interwebs for the answer, here it is:<\/p>\n<p><a href=\"http:\/\/www.qtforum.org\/article\/30063\/qt-opengl-resolution.html?s=404deefd560e1ab54cce082517049711d0fdb836#post100696\" target=\"_blank\" rel=\"noopener\">http:\/\/www.qtforum.org\/article\/30063\/qt-opengl-resolution.html?s=404deefd560e1ab54cce082517049711d0fdb836#post100696<\/a><\/p>\n<p>First, you&#8217;re going to need to download the <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=8279\" target=\"_blank\" rel=\"noopener\">Windows SDK<\/a> to get the proper c++ header files to reference. In this particular case, you&#8217;re going to want to reference &#8220;windows.h&#8221; like so:<\/p>\n<blockquote><p><code>#include \"windows.h\"<\/code><\/p><\/blockquote>\n<p>And then access the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/dd183411(v=vs.85).aspx\" target=\"_blank\" rel=\"noopener\">ChangeDisplaySettings<\/a> function from the Windows API like so:<!--more--><\/p>\n<blockquote><p><code>DEVMODE *dm=new DEVMODE();<br \/>\nEnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,dm);<br \/>\ndm-&gt;dmPelsWidth=(unsigned long)800;<br \/>\ndm-&gt;dmPelsHeight=(unsigned long)600;<br \/>\nChangeDisplaySettings(dm,CDS_FULLSCREEN);<\/code><\/p><\/blockquote>\n<p>And last but not least, you need to set your form\/widget into fullscreenMode like so:<\/p>\n<blockquote><p><code>this.setFullScreen();<\/code><\/p><\/blockquote>\n<p>And what you get is the intended, most importantly OPTIMIZED minimal screen for drawing your graphics to. The idea is you don&#8217;t want to draw to fill up the end-user&#8217;s high resolution screen unless you have to, especially when it&#8217;s a simple 2D game.<\/p>\n<p>And if you want to return to you default display resolution:<\/p>\n<blockquote><p><code>ChangeDisplaySettings(NULL, 0); \/\/Windows API call<\/p>\n<p>\/\/Reset Qt window state<br \/>\nthis->setWindowState(Qt::WindowNoState);<br \/>\nthis->move(0,0); \/\/in case it was moved out of reach<br \/>\n<\/code><\/p><\/blockquote>\n<p>But do note, this isn&#8217;t a complex implementation. If your local display driver, say Nvidia or ATI graphics driver is broken, then it won&#8217;t auto-magically fix the aspect ratio or whatever. That&#8217;s the case with my Windows 7 development machine and I have to set it to 640&#215;480 manually via Nvidia Control Panel. Otherwise, this Windows API code only changes the resolution.<\/p>\n<p>Oh, and before I forget and you noobs scream faulty coding, don&#8217;t forget to code somekind of escape mechanism to return back to normal. For example, set up the <code>keyPressed<\/code> event on the form\/widget to capture the ESCAPE key so that you can exit\/close the application, thus returning your resolution back to what it originally was. I don&#8217;t know if this is a given, but it seems to work like that on Windows Vista and Windows 7.<\/p>\n<p>Otherwise, I make no promises of it being safe code. But if it works for you, have fun.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you, too, are scouring the Interwebs for the answer, here it is: http:\/\/www.qtforum.org\/article\/30063\/qt-opengl-resolution.html?s=404deefd560e1ab54cce082517049711d0fdb836#post100696 First, you&#8217;re going to need to download the Windows SDK to get the proper c++ header files to reference. In this particular case, you&#8217;re going to want to reference &#8220;windows.h&#8221; like so: #include &#8220;windows.h&#8221; And then access the ChangeDisplaySettings function from &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/eastfist.com\/qt_tutorials\/how-to-change-screen-resolution-in-windows-using-qt\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to change screen resolution in Windows using Qt&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-qt-2"],"_links":{"self":[{"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":9,"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":332,"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/posts\/150\/revisions\/332"}],"wp:attachment":[{"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eastfist.com\/qt_tutorials\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}