fastest and best way to add scrollbar to a widget in qt - c++

I have a widget implemented with Qt5.0 but it is too large and does not have any scroll bars? how can I add it with minimum lines of codes?

If you don't want to put your widget in a QScrollArea, you can make your widget a descendent of QScrollArea itself. All of the Qt item views do this (QListView etc).

Related

Qt - How to put existing widgets and qscrollbar inside a QScrollArea

I'm a newbie in Qt.
I'm making a notepad with a ribbon:
And I wanted to make appear a QScrollBar when I resize the Window and I know that I have to use a QScrollArea for it.
My question is, how do I add existing widgets to a QScrollArea and make appear a QScrollBar when needed?
It doesn't look to me like your widgets are aligned in any form of layout. From designer, these button at the top allow you to put widgets in layouts:
Once your widgets are in their necessary layouts, make a new QScrollArea (either by doing QScrollArea *myArea = new QScrollArea() and adding it to a layout manually, or by dragging and dropping it in the designer). It should be as drag and drop as everything else you've encountered so far. You will want to set the vertical scroll policy to never scroll and set the contents margins of the scroll area's widget to 0.
But this begs the question, how savvy are you with GUI programming outside of Qt? You will run into a lot of obstacles from here on out if you can't grasp the concept of layouts and so on.
In case you don't know how layouts work, I suggest you look at the documentation. It's a good rule of thumb to check the docs and look for existing questions before asking. Manually setting the X and Y of widgets is a long-gone practice.

Qt dock neighbour widget behaviour

I have two Qt widgets in the window. One of them is QDockWidget, and another one is just QWidget.
When I drag the QDockWidget, the default behaviour of the another widget is moving without changing its size. And I want it to fill the whole window except dock widget, and to change its size programmatically when I drag QDockWidget. Hwo to do it better?
The solution was to set container horizontal policy as "fixed"

How to hide/show a QLabel and QTextEdit at the same time in my Qt application?

I am working on a hide/show feature for my console in my Qt GUI application. The console consists of 2 widgets; QLabel and QTextEdit. Do I need to add the QLabel and QTextEdit to a QWidget in order to show/hide them, or is there a better way?
So basically I am looking for a container such as 'JPanel' in Java...
Do I need to add the QLabel and QTextEdit to a QWidget in order to show/hide them, or is there a better way?
Multiple methods are possible here. You can, as you suggest, create a parent QWidget and add the QLabel and QTextEdit to a QWidget. Calling show and hide on the parent widget will affect its children.
Another method would be to have a slot function, which when an action is called, the slot calls show / hide on the 2 widgets.
Neither is right or wrong and depends upon the overall design of your application.
Ok, I think you need to use a layout (horizontal / vertical):
The simplest way to arrange objects on a form is to place them in a
horizontal or vertical layout. Horizontal layouts ensure that the
widgets within are aligned horizontally; vertical layouts ensure that
they are aligned vertically.
Horizontal and vertical layouts can be combined and nested to any
depth. However, if you need more control over the placement of
objects, consider using the grid layout.

Allow user to resize widgets at runtime in QT5

I have an application written in C++/QT5 with a QListView widget within a QHBoxLayout within a QGroupBox. There is also a QTabWidget in the main window. I would like the user to be able to resize the QListView widget by clicking and dragging and for the other items to automatically resize themselves accordingly.
I feel like this should be something that is easily done within the framework of QT5, but I can't for the life of me find a way. Even having a border on the list view that I can resize within the code of my application would be a start.
Thanks to jhnnslschnr I was able to solve this via the QSplitter widget. If you're using QtCreator as I was, you can use QSplitter simply by Ctrl-clicking the widgets you want in the splitter and then selecting "Lay out horizontally (vertically) in splitter". The user can now select the partitioning at run-time.

Make QVBoxLayout scrollable using QScrollArea

I have a QVBoxLayout which has content dynamically added to it. I simply want to make that layout scrollable as the content overflows. What is the correct way to achieve this in Qt Designer, or do I need code as well?
I've seen a mixed bag of examples, but none get low level enough to show exactly what needs to be done.
Thanks!
I have found a solution by doing the following.
In Qt Design view, create a QScrollArea. Then drag your existing QVBoxLayout into the QScrollArea. Right-click inside the QScrollArea (not inside the layout) and select "Apply Layout". Then choose a layout (I chose a vertical layout). That's it.
Hope this helps!