Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Border lines around QOpenGLWidgets in Qt6.
Forum Updated to NodeBB v4.3 + New Features

Border lines around QOpenGLWidgets in Qt6.

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 227 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ihmin
    wrote on last edited by
    #1

    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.

    border.png

    Below is the code to reproduce the error.
    sample code download

    main.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_H
    

    gltest.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 ();
    }
    
    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved