#include#include int main() { QDesktopWidget *desktop = QApplication::desktop(); int width = desktop->width(); std::cout << "Desktop width: " << width << std::endl; return 0; }
#includeThis example creates a simple window widget and sets its geometry to match the desktop screen width and a fixed height of 400 pixels. Package/library: Qt C++ library.#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; QDesktopWidget *desktop = QApplication::desktop(); int width = desktop->width(); window.setGeometry(0, 0, width, 400); window.show(); return app.exec(); }