# renderWindow.SetSize() limits?

**URL:** https://discourse.vtk.org/t/renderwindow-setsize-limits/9373
**Category:** Support
**Tags:** python
**Created:** [September 16, 2022, 5:49pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373 "2022-09-16T17:49:45Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [September 16, 2022, 5:49pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/1 "2022-09-16T17:49:45Z")

</div>

I have been playing around with different sizes for the renderWindow… I use SetSize and then used .GetSize() to get back the values. If I did this without starting any rendering, I was able to set any dimensions to the renderWindow, however, if I rendered the size eventually had a limit (e.g. I set it to 2001, 801) and got back (1540, 801). How would I determine the limits of a renderWindow then?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 16, 2022, 8:01pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/2 "2022-09-16T20:01:50Z")

</div>

As far as I understand, VTK itself doesn’t restrict the size of the window. VTK simply requests a certain size of window from the operating system, and then accepts whatever size the operating system provides.

It might be possible to find the maximum size by calling `GetScreenSize()` and then subtracting the number of vertical and horizontal pixels needed for menus, borders, and other decorations. But this is fiddly and not very robust.

VTK applications often rely on a GUI toolkit such as Qt to handle window sizing in situations like the one that you’re describing.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 16, 2022, 8:22pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/3 "2022-09-16T20:22:28Z")

</div>

Just adding a bit more detail: the Qt `QScreen` class has a property called `availableGeometry` that provides the maximum size available for top-level windows. I’ve used `availableGeometry` in my own applications and it works well. VTK itself has no such method.

---

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [September 18, 2022, 10:46am UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/4 "2022-09-18T10:46:21Z")

</div>

Thanks David,  
I still cannot get my head around the fact that there is nothing regarding this issue.

Here is part of the code I have (the part that has to do with the rendering of the window):

```auto
# Visualize.
mapper = vtkDataSetMapper()
mapper.SetInputData(uGrid)

actor = vtkActor()
actor.GetProperty().SetColor(colors.GetColor3d("PeachPuff"))
actor.SetMapper(mapper)

renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.SetSize(1801,801)
renderWindow.SetWindowName("Hexahedron")
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)

renderer.AddActor(actor)
renderer.SetBackground(colors.GetColor3d("BkgColor"))
renderer.SetActiveCamera(camera)
renderWindow.Render()
renderWindowInteractor.Start()

```

And this is my following line:

```auto
renderWindow.GetSize()

```

with the following result: `(1540, 801)`

I am able to get windows larger than that so I am still trying to figure this out???

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 18, 2022, 1:56pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/5 "2022-09-18T13:56:11Z")

</div>

> I am able to get windows larger than that so I am still trying to figure this out???

In order to help me understand better, what is the size of the “larger window” that you can get? And how do you get it? And what is your screen size? What operating system are you using (what does renderWindow.GetClassName() return?)

---

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [September 18, 2022, 4:06pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/6 "2022-09-18T16:06:45Z")

</div>

Thanks David. The operating system is windows. I get back is vtkWin32OpenGLRenderWindow. So ‘physically’ I should be able to get 1920 x 1080 (If I am interpreting things correctly).

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 18, 2022, 4:22pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/7 "2022-09-18T16:22:27Z")

</div>

You won’t be able to get 1920 x 1080 because when you call `renderWindow.SetSize()`, you are requesting the internal, drawable size of the window. Windows needs room to add the window decorations, such as the title bar and any window borders.

---

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [September 18, 2022, 4:27pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/8 "2022-09-18T16:27:17Z")

</div>

Hi David,

I just checked using `renderWindow.GetScreenSize()` and got (1536, 864) is that all my laptop can provide?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 18, 2022, 4:37pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/9 "2022-09-18T16:37:01Z")

</div>

Since 1536 x 864 is a 16:9 ratio, it seems reasonable that it’s the true screen size. It’s a resolution that makes sense for a laptop.

You can check the display control panel on your laptop to see what the true resolution of your display is.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [September 19, 2022, 2:49pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/10 "2022-09-19T14:49:38Z")

</div>

Hello,

I attached a 3159 x 1685 screen capture of a VTK canvas (in a Qt desktop program). I can resize it to whatever size I want, hence, whatever issue you’re having it is certainly not caused by VTK. Maybe the GUI system that creates the default window that backs `vtkRenderWindow`. Maybe that’s the resolution of your screen.

[VTK\_in\_4K\_display.zip](https://discourse.vtk.org/uploads/short-url/8cdkG9xwpWUXjivbUN1FBAeXJEh.zip) (799.6 KB)

regards,

Paulo

---

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [September 20, 2022, 8:19am UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/11 "2022-09-20T08:19:42Z")

</div>

Thank you Paulo for pointing this out!  
Any idea how I can determine what GUI system I am using? What is the default for VTK?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [September 20, 2022, 2:07pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/12 "2022-09-20T14:07:14Z")

</div>

Hi,

I believe the fallback case is a GLUT window. GLUT is a lightweight toolkit that provides very basic GUI functionality so unexperienced users and students can roll out their OpenGL applications without cumbersome GUI programming getting in the way. I’ve seen people having trouble with GLUT window sizing before but I’ve never heard of any hard limits. But I don’t work with GLUT since my undergrad years decades ago. As far as I know, OpenGL works with the limits returned by the OpenGL API backend, that is, the graphics driver. So, make sure your graphics driver is up-to-date and/or your graphics hardware is not too old.

In essence, you have to ask OpenGL what is the maximimum viewport size of your system. OpenGL API defines the C function `glGetIntegerv()` ([Função glGetIntegerv (Gl.h) - Win32 apps | Microsoft Learn](https://learn.microsoft.com/pt-br/windows/win32/opengl/glgetintegerv)). You pass the `GL_MAX_VIEWPORT_DIMS` constant to it to query the maximum viewport size in pixels. Since you’re in Python, I believe you can `pip install` PyOpenGL in your system to access OpenGL and use a code like this (untested):

```python
import OpenGL.GL as gl

(...)

viewport_max_sizes = gl.glGetIntegerv(gl.GL_MAX_VIEWPORT_DIMS)

```

From there, you can use Python’s exploration programming capabilities to get your viewport max sizes.

I hope this helps,

Paulo

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 20, 2022, 2:47pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/13 "2022-09-20T14:47:47Z")

</div>

VTK doesn’t use GLUT. On Windows, It uses the native [Win32 API](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindoww) and [WGL](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-wglcreatecontext).

The place in the code where VTK creates a native Win32 window is here (in vtkWin32RenderWindow) and if my understanding is correct, any limitations on the size you get are due to display/desktop limits and are unrelated to OpenGL.

Since vtkWin32RenderWindow uses old Win32 API calls, I’m not sure how it will respond to recent Windows features like the “Scale” the Display Settings. It would be worth going to your display settings and changing the “Scale” to 100% to see if it changes the behavior of VTK. I notice, for example, that 1536 is 1920/1.25, so maybe your current “Scale” setting is 125%?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [September 20, 2022, 2:51pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/14 "2022-09-20T14:51:39Z")

</div>

> [@dgobbi](#):
>
> any limitations on the size you get are due to display/desktop limits and are unrelated to OpenGL

I beg to disagree here. There is indeed a maximum viewport size. In one of my computers it is 8192 x 8192 (see my post above on how to query it), which exceeds by far its 4K display, but the limit is there.

---

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [September 21, 2022, 2:46pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/15 "2022-09-21T14:46:14Z")

</div>

Thank you both for your comments.

@dgobbi David, you were right pointing out the issue about the scale factor. Indeed the scale was set to 125%. I set the scale to 100% and voilà I got a resolution of 1920x 1080 which appears the maximum my laptop can achieve (it is new laptop just bought it last month).

However, I am still interested in this question as the resolution affects the analysis I am interested in conducting. It would appear, following @Paulo_Carvalho that using Qt it might be possible to achieve larger resolutions. Is setting VTK with Qt hard to achieve? Can this be done using Python?

Thanks again both of you for your help and interest!!!

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [September 21, 2022, 9:39pm UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/16 "2022-09-21T21:39:12Z")

</div>

Hello,

Based on my experience, Qt certainly never imposed any limits. This does not mean that you can have limitless resolution. As stated above, the limit comes from underlying systems, namely the OpenGL backend, the OS, etc.

Please, take a look at this: [Minimal working example of VTK embedding in PyQt with Qt5 · GitHub](https://gist.github.com/paskino/7b7ed6e4541d682bd5ce5d521505dd8f)

regards,

Paulo

---

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [September 23, 2022, 10:21am UTC](https://discourse.vtk.org/t/renderwindow-setsize-limits/9373/17 "2022-09-23T10:21:27Z")

</div>

Great!

Thank you for the example, very useful!
