Making Qt Widgets Stretch and Scale w/ Main Window - c++

I'm wondering if there is a way to make Qt widgets within a QMainWindow widget stretch and scale as the size of the main window is stretched and shrunk. Basically, I'd like the entire window and it's contents to have the same appearance except for size:
At the only way I can think to accomplish this is to get the size of the main window, do the math for every single widget, and reset their sizes any time the main window size is changed, but I'm thinking there's an easier way.

I like this video tutorial on youtube. I'll help you create a layout using QLayout classes. If you use QtCreator/Designer, you can also take a look at the auto-generated ui_MainWindow.XXX file that will clue you in on how it uses some of the UI classes.
As always, QtCreator/Designer has a bunch of hints and tips so you should be able to dig up from the documentation that's embedded in the application.

Related

How to align the button in Gtkmm?

I am using Ubuntu OS.
I am new to GTKMM GUI building application.
I am following the tutorials which they have on their websites.
https://developer.gnome.org/gtkmm-tutorial/stable/sec-helloworld.html.en
I can resize the window with helloworld.set_default_size(500,500);
but I cannot move the position of button("hello world").
It is always aligned at center.
I tried with m_button.set_alignment(0.0,0.0) but nothing seems to be working.
Why it is that much difficult to move button to any position.?
kindly suggest some solution if available.
If you want to place a widget like a button, you have to use some container widget like Gtk::Boxor Gtk::Grid. Inside such container widgets you can place you child widget as you like, but typically not directly per point position.
The container widgets use some internal logic to order and resize the contained widgets.
From the documentation:
Many GUI toolkits require you to precisely place widgets in a window, using absolute positioning, often using a visual editor. This leads to several problems: ...
gtkmm uses the packing system to solve these problems.
You can find the full documentation here:
Multi-item widgets
I did not know if there is a container widget which allows direct positioning by giving a point position. If someone has an additional hint, let us know!
Sometimes automatic is better than manual handling, but sometimes it is not :-)

How to automatically zoom buttons and everything in Qt on qWidget.showFullScreen()?

I want to resize everything when i show it in full screen automatically keeping aspect ratio. How can i do it. i use PyQt4 but if you know of C++ then also please tell me.
Hope the code will be not more than 2-3 lines.
Thanks
I suppose you've implemented static layouts with fixed widget sizes and positions in your dialogs/windows. In order to resize the widgets with the window, what you need to do is using dynamic layouts. You best use Qt Designer for the dialog design, else setting up any non-trivial layout can get rather toilsome.

Strange delayed painting with Qt5 on Windows

I'm using Qt5 in Windows. I just created a simple little widgets project in Qt Creator. I have a QMainWindow with a text edit widget inside. I enabled vertical layout, so the text edit consumes the full size of the inside of the main window (which is what I want, I'm trying to create a small notepad app).
As I drag the bottom right corner of the main window during the preview (I click the green triangle in the bottom left) I'm seeing a slight delay in the child widget's resizing. It doesn't exactly resize with the parent window on the same render frame (it seems like it is 1-2 render frames behind).
I remember years ago dealing with render lag like this in old school Win32 API. I remember I had to do double-buffered rendering into an offscreen bitmap to fix it (or something along those lines; been a long time).
Is there a way to fix this "render lag" in Qt? I can only imagine this is specific to Windows and might not impact other platforms, although I have not tested. If I need to provide more information let me know.
It is likely a Windows problem, not Qt's. The more GUI-heavy your window is the more noticeable it is.
I investigated the same issue a while ago. We had a rather GUI-heavy window, with several widgets displaying 2D and 3D views of data. Resizing the window using lower-right corner resulted in a resize-redraw horror. Unfortunately it looks like the problem is not Qt related but rather the way that Windows handles redrawing a resized window. I was able to notice the problem even in the file explorer on Windows 7. Qt is indeed using double buffering by default (as mentioned in the comment by #Bim). I also tried explicitly triggering Qt's repaint events. This helped a little, but did not solve the problem. So after many efforts we just decided to live with it.

Resize size of Main Window depending on Hardware in Qt?

I have developed my Application with most of the Widgets in Qt Creator's Designer module.
I have hard coded the sizes of my widgets depending on how they appeared on my laptop. Yesterday when I ran the application on my Desktop (lower screen resolution than laptop) some of the Main Window widgets were not visible & on startup there was horizontal scrollbar & I had to scroll to see those widgets; which is not the case on my laptop.
I have 2 problems:
Is it possible to resize all of my widgets (even those which are added run time by code) by using some resize factor? Maybe at startup I will get the screen resolution of Hardware in which application is running & then create a ratio of that with resolution of my laptop. Is it possible to multiply this factor to all widgets without adding code for each widget?
How do I get the resolution of the Screen in which my Application is running?
PS: I would like to know the defacto method of solving this problem...
Thank You.
You could try a function like this:
resize(theDesktop->screenGeometry().width()*PERCENTAGE_OF_MONITOR_WIDTH_FOR_SCREEN, theDesktop->screenGeometry().height()*PERCENTAGE_OF_MONITOR_HEIGHT_FOR_SCREEN);
Resize is a member function of the QWidget class and the PERCENTAGE_OF_MONITOR variables would be whatever percentage of the monitor you want your application to take up.
theDesktop is of the type QDesktopWidget.
You should use Layouts to manage the size policy of your widgets.
Qt layouts automatically position and resize widgets when the amount of space
available for them changes, ensuring that they are consistently
arranged and that the user interface as a whole remains usable."
You could also check this question for more information regarding layout machanisms in Qt.
Qt website has got excelent documentation on the subject. You can start here for more information on working with layouts in Qt Designer.

QtDesigner layout confusion

I've been playing around with QtDesigner for some time now, but I can't find a real solution for my desired layout.
Here's what I'm aiming for, kind of an Eclipse RCP-like layout:
Five drag&dropable widgets which can be rearranged and whatnot (so Dockwidgets). Thats what happend in above screenshot, I just pulled five Dockwidgets into the Mainwindow and populated them with Items. But the problem is that Dockwidgets only snap to the edges of the Mainwindow, and leave space to CentralWidget, which you see in the middle. Is there some way to add a containing widget to the center and fill it with DockWidgets?
On a side note: Is it feasable to do something like this in the Designer? I see why this program is useful, as GUIs can be set up and changed extremly fast, but I feel like stripped of any power on the exact look. I'm kinda itching to (attempt to) write the GUI by hand, because I'm feeling so powerless! :-)
P.S.:How can the screenshot be scaled? It seems overly huge
Unfortunately no. As it says in the documentation
Dock windows are secondary windows placed in the dock widget area around the central widget in a QMainWindow.