Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • VTK VTK
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 778
    • Issues 778
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 210
    • Merge requests 210
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • VTK
  • VTKVTK
  • Merge requests
  • !3973

Support fractional device pixel ratio in native Qt widget

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Elvis Stansvik requested to merge estan/vtk:fractional-dpi-scaling into master Feb 26, 2018
  • Overview 39
  • Commits 1
  • Pipelines 3
  • Changes 4

When fractional DPI scaling is used, the VTK render window / interactor has the wrong size because it's calculated from devicePixelRatio() which is an integer API returning a rounded value.

Starting with Qt 5.6, there's a devicePixelRatioF() API that can return a non-integer device pixel ratio. This makes sure the new API is used in QVTKOpenGLNativeWidget, when available.

The problem was first reported by me on the VTK developers mailing list:

https://www.vtk.org/pipermail/vtk-developers/2018-February/035826.html

Test Program (Sphere.cxx)

#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkGenericOpenGLRenderWindow.h>

#include <QApplication>
#include <QPointer>
#include <QSurfaceFormat>

#include <QVTKOpenGLNativeWidget.h>

int main(int argc, char *argv[])
{
  QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());

  QApplication app(argc, argv);

  vtkNew<vtkGenericOpenGLRenderWindow> window;
  QPointer<QVTKOpenGLNativeWidget> widget = new QVTKOpenGLNativeWidget();
  widget->SetRenderWindow(window.Get());

  // Create a sphere
  vtkSmartPointer<vtkSphereSource> sphereSource = 
    vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->SetCenter(0.0, 0.0, 0.0);
  sphereSource->SetRadius(5.0);

  vtkSmartPointer<vtkPolyDataMapper> mapper = 
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(sphereSource->GetOutputPort());

  vtkSmartPointer<vtkActor> actor = 
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  vtkSmartPointer<vtkRenderer> renderer = 
    vtkSmartPointer<vtkRenderer>::New();
  window->AddRenderer(renderer);

  renderer->AddActor(actor);

  widget->resize(300, 300);
  widget->show();

  return app.exec();
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
PROJECT(dpibug)
 
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
 
add_executable(Sphere MACOSX_BUNDLE Sphere.cxx)
 
if(VTK_LIBRARIES)
  target_link_libraries(Sphere ${VTK_LIBRARIES})
else()
  target_link_libraries(Sphere vtkHybrid vtkWidgets)
endif()

Output Before (Qt 5.9.5, run with QT_SCREEN_SCALE_FACTORS=1.4 ./Sphere)

before

Notice how the render window has the wrong size.

Output After (Qt 5.9.5, run with QT_SCREEN_SCALE_FACTORS=1.4 ./Sphere)

after

The render window is now the correct size.

Edited Oct 24, 2018 by Elvis Stansvik
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: fractional-dpi-scaling