diff -ur gnuplot-5.2.8.orig/config/mingw/Makefile gnuplot-5.2.8/config/mingw/Makefile
--- gnuplot-5.2.8.orig/config/mingw/Makefile	2023-08-18 15:53:34.185447448 -0400
+++ gnuplot-5.2.8/config/mingw/Makefile	2023-08-18 16:03:31.492411188 -0400
@@ -463,11 +463,13 @@
 endif
 
 ifdef QT
-	QT_LIBS = -lQt5Core -lQt5Gui -lQt5Network -lQt5Svg -lQt5Widgets -lQt5PrintSupport -lqtmain
+	QT_VERSION ?= 5
+	QT_EXTRA_LIBS ?= -lqtmain
+	QT_LIBS = -lQt$(QT_VERSION)Core -lQt$(QT_VERSION)Gui -lQt$(QT_VERSION)Network -lQt$(QT_VERSION)Svg -lQt$(QT_VERSION)Widgets -lQt$(QT_VERSION)PrintSupport $(QT_EXTRA_LIBS)
 	QT_CXXFLAGS =  -I$(QT_DIR)/include -I$(QT_DIR)/include/Qt -I$(QT_DIR)/include/QtCore -I$(QT_DIR)/include/QtGui
 	QT_CXXFLAGS += -I$(QT_DIR)/include/QtWidgets -I$(QT_DIR)/include/QtNetwork
-	QT_CXXFLAGS += -I$(QT_DIR)/include/QtSvg -DQTGNUPLOT_DATA_DIR=\"$(GNUPLOT_QT_DIR)\"
-	QT_LDFLAGS = -L$(QT_DIR)/lib
+	QT_CXXFLAGS += -I$(QT_DIR)/include/QtSvg -DQTGNUPLOT_DATA_DIR=\"$(GNUPLOT_QT_DIR)\" $(QT_EXTRA_CXXFLAGS)
+	QT_LDFLAGS = -L$(QT_DIR)/lib $(QT_EXTRA_LDFLAGS)
 #
 	CFLAGS += -DQTTERM -DQT_NO_OPENGL
 	TERMLIBS += $(QT_LIBS)
diff -ur gnuplot-5.2.8.orig/src/qtterminal/qt_term.cpp gnuplot-5.2.8/src/qtterminal/qt_term.cpp
--- gnuplot-5.2.8.orig/src/qtterminal/qt_term.cpp	2023-08-18 15:53:34.166446304 -0400
+++ gnuplot-5.2.8/src/qtterminal/qt_term.cpp	2023-08-18 16:05:08.522243654 -0400
@@ -76,6 +76,7 @@
 #include "qt_term.h"
 #include "QtGnuplotEvent.h"
 #include "QtGnuplotApplication.h"
+#include <QTextCodec>
 #include "qt_conversion.cpp"
 
 void qt_atexit();
diff -ur gnuplot-5.2.8.orig/src/qtterminal/QtGnuplotScene.cpp gnuplot-5.2.8/src/qtterminal/QtGnuplotScene.cpp
--- gnuplot-5.2.8.orig/src/qtterminal/QtGnuplotScene.cpp	2023-08-19 07:00:17.830930697 -0400
+++ gnuplot-5.2.8/src/qtterminal/QtGnuplotScene.cpp	2023-08-19 07:29:58.464228586 -0400
@@ -649,7 +649,7 @@
 	{
 		QFontMetrics metrics(m_font);
 		int par1 = (metrics.ascent() + metrics.descent());
-		int par2 = metrics.width("0123456789")/10.;
+		int par2 = metrics.horizontalAdvance("0123456789")/10.;
 		m_eventHandler->postTermEvent(GE_fontprops, 0, 0, par1, par2, m_widget);
 	}
 	else if (type == GEDone)
@@ -803,7 +803,7 @@
 
 	int button = 0;
 	     if (event->button()== Qt::LeftButton)  button = 1;
-	else if (event->button()== Qt::MidButton)   button = 2;
+	else if (event->button()== Qt::MiddleButton)   button = 2;
 	else if (event->button()== Qt::RightButton) button = 3;
 
 	m_eventHandler->postTermEvent(GE_buttonpress, 
@@ -892,7 +892,7 @@
 
 	int button = 0;
 	     if (event->button()== Qt::LeftButton)  button = 1;
-	else if (event->button()== Qt::MidButton)   button = 2;
+	else if (event->button()== Qt::MiddleButton)   button = 2;
 	else if (event->button()== Qt::RightButton) button = 3;
 
 	qint64 time = 301;	/* Only used the first time in, when timer not yet running */
diff -ur gnuplot-5.2.8.orig/src/qtterminal/QtGnuplotScene.h gnuplot-5.2.8/src/qtterminal/QtGnuplotScene.h
--- gnuplot-5.2.8.orig/src/qtterminal/QtGnuplotScene.h	2023-08-19 07:00:17.831930754 -0400
+++ gnuplot-5.2.8/src/qtterminal/QtGnuplotScene.h	2023-08-19 07:31:27.261363017 -0400
@@ -51,7 +51,7 @@
 
 #include <QGraphicsScene>
 #include <QGraphicsItemGroup>
-#include <QTime>
+#include <QElapsedTimer>
 
 class QtGnuplotEnhanced;
 class QtGnuplotWidget;
@@ -106,7 +106,7 @@
 	QPoint  m_currentBoxOrigin;
 	QPoint  m_textOffset;
 	double  m_currentZ;
-	QTime   m_watches[4];
+	QElapsedTimer   m_watches[4];
 	int     m_currentPlotNumber;
 	bool    m_inKeySample;
 	bool    m_preserve_visibility;
diff -ur gnuplot-5.2.8.orig/src/qtterminal/QtGnuplotWidget.cpp gnuplot-5.2.8/src/qtterminal/QtGnuplotWidget.cpp
--- gnuplot-5.2.8.orig/src/qtterminal/QtGnuplotWidget.cpp	2023-08-19 07:00:17.831930754 -0400
+++ gnuplot-5.2.8/src/qtterminal/QtGnuplotWidget.cpp	2023-08-19 07:16:25.518277987 -0400
@@ -128,7 +128,7 @@
 
 void QtGnuplotWidget::setViewMatrix()
 {
-	m_view->resetMatrix();
+	m_view->resetTransform();
 }
 
 void QtGnuplotWidget::processEvent(QtGnuplotEventType type, QDataStream& in)
@@ -146,7 +146,7 @@
 		QSize s;
 		in >> s;
 		m_lastSizeRequest = s;
-		m_view->resetMatrix();
+		m_view->resetTransform();
 		QWidget* viewport = m_view->viewport();
 /*		qDebug() << "QtGnuplotWidget::processEvent Size request" << s << size() << " / viewport" << m_view->maximumViewportSize();
 		qDebug() << " widget size   " << size();
@@ -291,8 +291,8 @@
 	QPrinter printer;
 	printer.setOutputFormat(QPrinter::PdfFormat);
 	printer.setOutputFileName(fileName);
-	printer.setPaperSize(QSizeF(m_scene->width(), m_scene->height()), QPrinter::Point);
-	printer.setPageMargins(0, 0, 0, 0, QPrinter::Point);
+	printer.setPageSize(QPageSize(QSizeF(m_scene->width(), m_scene->height()), QPageSize::Point));
+	printer.setPageMargins(QMarginsF(0,0,0,0), QPageLayout::Unit(QPrinter::Point));
 	QPainter painter(&printer);
 	painter.setRenderHints(renderHints());
 	m_scene->render(&painter);
diff -ur gnuplot-5.2.8.orig/src/qtterminal/QtGnuplotItems.cpp gnuplot-5.2.8/src/qtterminal/QtGnuplotItems.cpp
--- gnuplot-5.2.8.orig/src/qtterminal/QtGnuplotItems.cpp	2023-08-19 07:54:01.475635227 -0400
+++ gnuplot-5.2.8/src/qtterminal/QtGnuplotItems.cpp	2023-08-19 07:56:36.531724069 -0400
@@ -111,7 +111,7 @@
 qreal QtGnuplotEnhancedFragment::width() const
 {
 	QFontMetricsF metrics(m_font);
-	return metrics.width(m_text);
+	return metrics.horizontalAdvance(m_text);
 }
 
 void QtGnuplotEnhancedFragment::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
