Border lines around QOpenGLWidgets in Qt6.
-
Hello.
I am currently using Qt version 6.7.2 on Windows 10 + Msys2 environment.
I have written a very simple code for QOpenGLWidget.
However, in Qt6, when I set the screen DPI to 125%, the RED border lines appear and disappear on the top and right when resizing the window.
Is this a bug in Qt?
However, the same code works fine in Qt5.
Below is the code to reproduce the error.
sample code downloadmain.cpp
#include <QGuiApplication> #include "mainwindow.h" #include "gltest.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QSurfaceFormat format; format.setRenderableType(QSurfaceFormat::OpenGL); format.setVersion(4, 3); format.setProfile(QSurfaceFormat::CompatibilityProfile); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setDepthBufferSize(32); format.setStencilBufferSize(4); format.setSwapInterval(1); QSurfaceFormat::setDefaultFormat(format); MainWindow *w; w = new MainWindow(0); w->show(); int ret = app.exec(); return ret; }mainwindow.cpp
#include "mainwindow.h" #include "gltest.h" MainWindow::MainWindow(QWidget *parent) { setCentralWidget(new GLTest(this)); } MainWindow::~MainWindow() { }mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QApplication> #include <QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent); ~MainWindow(); }; #endif // MAINWINDOW_Hgltest.h
#pragma once #include <QOpenGLWidget> #include <QOpenGLWindow> #include <QOpenGLFunctions> #if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0) #include <QOpenGLExtensions> #else #include <QOpenGLVersionFunctionsFactory> #endif #include <QOpenGLBuffer> #include <QOpenGLShaderProgram> #include <QOpenGLVertexArrayObject> #include <QOpenGLFramebufferObject> #include <QSurfaceFormat> #include <QMatrix4x4> #include <QOpenGLFunctions_4_3_Compatibility> #define GLM_ENABLE_EXPERIMENTAL #include <glm/gtx/string_cast.hpp> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/type_ptr.hpp> #include <glm/gtx/transform.hpp> #include <glm/gtx/quaternion.hpp> #include <glm/gtx/normal.hpp> #include <glm/gtx/hash.hpp> #include <glm/gtx/intersect.hpp> #include <glm/gtx/closest_point.hpp> #include <glm/gtc/matrix_access.hpp> #include <glm/gtc/matrix_inverse.hpp> #include <glm/gtx/matrix_decompose.hpp> class GLTest : public QOpenGLWidget, protected QOpenGLFunctions_4_3_Compatibility { Q_OBJECT public: GLTest(QWidget *parent=nullptr); virtual ~GLTest(); void drawBackground(void); protected: void initializeGL() Q_DECL_OVERRIDE; void resizeGL(int width, int height) Q_DECL_OVERRIDE; void paintGL() Q_DECL_OVERRIDE; private: QOpenGLFunctions_4_3_Compatibility *m_ctx; glm::vec3 m_bg_color1; glm::vec3 m_bg_color2; glm::vec3 m_bg_color3; glm::vec3 m_bg_color4; };gltest.cpp
#include "gltest.h" #include <QOpenGLContext> GLTest::GLTest(QWidget *parent) : QOpenGLWidget(parent) { setObjectName("GLTest"); m_bg_color1 = glm::vec3(0.19f, 0.25f, 0.29f); m_bg_color2 = glm::vec3(0.19f, 0.25f, 0.29f); m_bg_color3 = glm::vec3(0.19f, 0.25f, 0.29f); m_bg_color4 = glm::vec3(0.19f, 0.25f, 0.29f); } GLTest::~GLTest() { } void GLTest::initializeGL() { initializeOpenGLFunctions(); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) m_ctx = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_3_Compatibility>(); #else m_ctx = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_4_3_Compatibility>(); #endif } void GLTest::paintGL() { m_ctx->glClearColor(1.0f, 0.0f, 0.0f, 1.0f); m_ctx->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); drawBackground(); } void GLTest::resizeGL(int width, int height) { m_ctx->glViewport(0, 0, width*devicePixelRatio(), height*devicePixelRatio()); } void GLTest::drawBackground(void) { m_ctx->glMatrixMode (GL_MODELVIEW); m_ctx->glPushMatrix (); m_ctx->glLoadIdentity (); m_ctx->glMatrixMode (GL_PROJECTION); m_ctx->glPushMatrix (); m_ctx->glLoadIdentity (); m_ctx->glShadeModel(GL_SMOOTH); m_ctx->glDisable(GL_DEPTH_TEST); m_ctx->glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); m_ctx->glBegin(GL_QUADS); m_ctx->glColor3fv(glm::value_ptr(m_bg_color1)); m_ctx->glVertex2f(-1.0, 1.0); m_ctx->glColor3fv(glm::value_ptr(m_bg_color2)); m_ctx->glVertex2f(-1.0, -1.0); m_ctx->glColor3fv(glm::value_ptr(m_bg_color3)); m_ctx->glVertex2f(1.0, -1.0); m_ctx->glColor3fv(glm::value_ptr(m_bg_color4)); m_ctx->glVertex2f(1.0, 1.0); m_ctx->glEnd(); m_ctx->glShadeModel(GL_FLAT); m_ctx->glEnable(GL_DEPTH_TEST); m_ctx->glPopMatrix (); m_ctx->glMatrixMode (GL_MODELVIEW); m_ctx->glPopMatrix (); }