Resize image to fit window in Qt - qt

I am using Qt to construct an application. My MainWindow consists of an image of a map which I would like to be resized to the fit the window. This means when the window gets smaller the image gets smaller and vice versa. When the user selects a point on that image I want to remove this feature. I am new to Qt and haven't been able to figure this out. I am using QGraphicsView for this.

QGraphicsView::fitInView

Related

JavaFX - imageview node only shows with window resize

I'm using JavaFX. When i add an imageview node to the stack pane and then run the application, I can only see the image after manually resizing the window (dragging the edge of the window with my mouse).
It will also show up if i setTranslateX or setTranslateY the image away from its original location. But if I want it to just stay there, I have to manually resize the window to see it. Has anyone encountered this? Is it a bug I just have to deal with?
Thanks

How to enable resizing of a window in Qt

I'm new to Qt and I'm trying to figure out a way to auto-resize in Qt. The goal is for the user to be able to drag the window to make it bigger and everything resizes to the size of the window. Does anyone have any tips?

Creating a permanent static overlay for QGraphicsView scene

I am making an app using Qt (currently 4.8) which displays a literal map from a large number of QGraphicsScene items. I would like to annotate the view with a scale. My requirement for the scale is that it is permanently fixed w.r.t the viewport widget. It needs to be updated whenever the view scale changes (zoom in, etc). There are other possible overlay items as well (compass, etc) so I'd prefer a generic solution.
I have looked at earlier questions around this which suggest:
using the ItemIgnoresTransform
using an overlay pixmap.
I tried IgnoresTransform but that way didn't work right: I couldn't figure out how to fix it in place in (say) the bottom corner of the viewport and was having some difficulty getting the text and lines always displaying in the correct size.
I scrapped that and subclassed QGraphicsView, adding an overlay pixmap by reimplementing the paintEvent (calls original one, then paints the overlay pixmap on top), and an alignment option to indicate where it goes. Coding some pixmap paint code produces a usable scale on the view. Yay! ... but it doesn't work with scrolls - I get "shattered" renderings of the scale all over, or sometimes no scale at all. I think this is because QGraphicsView::scrollViewportBy() uses viewport()->scroll() so I wondered if switching to ViewportSmartUpdate would help, but it doesn't help enough. I'd prefer not to switch to ViewportFullUpdate as that would likely slow the app down too much (there are millions of items in the scene and that would require a full repaint just to move around).
So. Any ideas from here? Would adapting my pixmap code to write to a new mostly-transparent Widget that is overlaid on the viewport be a better way?
Thanks for any help...
Though it may not be the best way of doing this, in the past I've added custom widgets to the window that holds the QGraphicsView / QGraphicsScene, which have the same graphic style as the QGraphicObjects in the scene. When the view is then used to move objects in the scene, or the scene itself, the items on the window remain in the same place.
Hope that helps.

Can't embed OpenGL window into QWidget with XReparentWindow

I'm trying to add better UI for an OpenGL-based program with Qt. Since I can modify that program it's not hard to get the window ID. So I think embedding it into a QWidget would be a good idea. However, it doesn't work like I expected:
After XReparentWindow is called, the OpenGL window lose its decoration, but the position didn't change.
If I use XConfigureWindow to move it to position (0, 0) relative to parent it goes to the top-left corner of the screen, but not the QWidget.
After reparenting, a third window can cover the QWidget, but nothing can cover the OpenGL window.
X11 reported no errors during the whole operation.
It seems the parent of the OpenGL window has been set to the root window instead of my QWidget. What should I do to make it work correctly?
You can replace your current OpenGL window with a QGLWidget which provides an OpenGL context and can be placed into a Qt window directly.
I'm not sure Qt supports XReparentWindow calls like that. The docs don't seem to say it does, so it's probably a bad idea to use it. You could try QWidget::create() instead.

Force widget resizing in Qt

I'm writing an image viewer, and I'd like some behavior from Qt:
imagine the viewer displays the image in a 256x256 box. Now I want that ctrl+Z do a zoom + resizing of the window; ie. show the 2x zoomed image in a 512x512 box, how can I do that?
Also, imagine know the user gave a certain shape to my viewer, and that he presses F10, I want to change the layout to display the viewer in the same size (if possible, eg not overflowing the screen) and add additional controls under it, and resize the complete widget in a way that the viewer widget does
Maybe you could use the QWidget::minimumSize property to change the widget minimal size.
If the size of your zoomed image gets bigger than the screen, you might have to put your widget into a QScrollArea.

Resources