diff --git a/scribus/main_nix.cpp b/scribus/main_nix.cpp
index a73325103..d7eac662a 100644
--- a/scribus/main_nix.cpp
+++ b/scribus/main_nix.cpp
@@ -25,6 +25,7 @@ for which a new license (GPL+exception) is in place.
 *                                                                         *
 ***************************************************************************/
 
+#include <cstring>
 #include <iostream>
 #include <csignal>
 
@@ -66,8 +67,24 @@ int mainApp(int argc, char **argv)
 {
 	emergencyActivated = false;
 
+	// Pre-scan argv for --no-gui/-g before creating QApplication,
+	// so we can select the offscreen platform plugin and prevent
+	// any window or dock icon from appearing
+	bool noGUI = false;
+	for (int i = 1; i < argc; ++i)
+	{
+		if (strcmp(argv[i], "--no-gui") == 0 || strcmp(argv[i], "-g") == 0)
+		{
+			noGUI = true;
+			break;
+		}
+	}
+
+	if (noGUI)
+		qputenv("QT_QPA_PLATFORM", "offscreen");
 #if !defined(Q_OS_MACOS)
-	qputenv("QT_QPA_PLATFORM", "xcb");
+	else
+		qputenv("QT_QPA_PLATFORM", "xcb");
 #endif
 
 	QImageReader::setAllocationLimit(1024);
diff --git a/scribus/main_win32.cpp b/scribus/main_win32.cpp
index 312bc3c3d..cd0ccb893 100644
--- a/scribus/main_win32.cpp
+++ b/scribus/main_win32.cpp
@@ -99,6 +99,18 @@ int main(int argc, char *argv[])
 	}
 #endif
 
+	// Pre-scan argv for --no-gui/-g before creating QApplication,
+	// so we can select the offscreen platform plugin and prevent
+	// any window from appearing
+	for (int i = 1; i < argc; ++i)
+	{
+		if (strcmp(argv[i], "--no-gui") == 0 || strcmp(argv[i], "-g") == 0)
+		{
+			qputenv("QT_QPA_PLATFORM", "offscreen");
+			break;
+		}
+	}
+
 	ScribusQApp::setAttribute(Qt::AA_EnableHighDpiScaling);
 	ScribusQApp::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
 	QImageReader::setAllocationLimit(1024);
