MFC equivalent of Qt QVBoxLayout widget - c++

I'd like to know how to position MFC controls in the dialog so that they stretch to fill free space in the dialog. In Qt it is possible to nest QVBoxLayout and QHBoxLayout widgets, I'm looking for something similar in MFC.
Additionally I'd be interested to know if there exists an MFC control similar to the Qt QTableWidget that can have other widgets nested in each cell.

Not difficult to find on the web..
Resizable layouts:
http://www.codeproject.com/KB/dialog/WndResizer.aspx
Not sure on the grid control with widgets in it, maybe this will do it with some modifications:
http://www.codeproject.com/KB/miscctrl/gridctrl.aspx

As far as I know, there is no layout managers in MFC. A big lack indeed...

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.

How to create QSplitter ui class via qt designer?

I am new to Qt and I need to implement a monitoring interface with the following considerations:
I have a main window, on which I should put multiple screens, qsplitter appears to be the best solution.
The interface provides user with the option of changing the number of cameras, so QSplitter should be created/re-created during run time.
The problem is that I have too many cameras to pre-define widgets for them, so I need to create QSplitter UI instances dynamically.
The problem is that I can't find QSplitter classes when using Qt Designer and creating QSplitter class programatically is not working as MainWindow has been created through Qt Designer (.ui).
I would like to hear any suggestions regarding this issue, if there are better approaches, please let me know.
In Qt Designer, the QSplitter is not a widget, but a Layout.
Select the widgets you want to include in the two splitter areas, then select Layout from the context menu (right mouse button) - you will find two entries Layout Horizontally in splitter and Layout Vertically in splitter to group the widgets in a vertical or in a horizontal splitter.
QSplitter isn't a strict UI element, it's essentially a parent element that controls child elements. If you want to do it through Designer you'd probably run into headaches, but the basic gist is you select a number of widgets to be controlled by it, and click the Layout Horizontally/Vertically in splitter button which is in the layout buttons group.
What you might be best doing is creating your child elements programmatically, creating your splitter programmatically, adding the child widgets with someSplitter->addWidget(...). In the Qt docs there's some sample code for this:
QSplitter *splitter = new QSplitter(parent);
QListView *listview = new QListView;
QTreeView *treeview = new QTreeView;
QTextEdit *textedit = new QTextEdit;
splitter->addWidget(listview);
splitter->addWidget(treeview);
splitter->addWidget(textedit);
http://doc.qt.io/qt-5/qsplitter.html#details
And if you really want to do it in Designer there's a guide here: http://www.bogotobogo.com/Qt/Qt5_Splitter.php
Although QSplitter is a widget, you can't create one directly in Qt Designer. It is only available for laying out pre-existing widgets - which does not fit your use-case, since you need to create child widgets dynamically.
However, you can work around this limitation by using widget promotion. This is a simple mechanism that allows you to add substitute classes to represent widgets that are not directly available in Qt Designer. The idea is that you add a widget that is most similar to the one you actually want (e.g. a QFrame is most similar to QSplitter) and then promote that to the substitute class which you have defined in your own header file. When uic finally generates the code, it will use your substitute class instead of the class of the widget added in Qt Designer (which just acts as a placeholder).
Note that when you create your substitute class in the Promoted Widgets dialog, the base class should be a QFrame, not a QSplitter. This is because you are extending a QFrame (i.e. your placeholder widget), rather than a QSplitter. Of course, you can define your substitute class to be anything you like.
Image is easier to understand.

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.

QT window within window?

I'm setting up a small code editor using QT and following this example. However, i'm curious on how to create windows within windows or widgets within widgets. I'm trying to achieve something similar to these:
http://i.stack.imgur.com/Vn8Ut.png
http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/Download-Visual-Studio-2013-while-your-f_1431E/image_4eb5427c-1ae7-4464-9c26-2282fe8d06c3.png
Is there an example of overlaying widgets like this?
Any alternative soloution for QMessagebox for IOS development (QWidget application only)?
I gave an example of getting another QWidget to be embedded and painted on top of another one. Let me know if you have any questions about how it was done.
The PopUp flag and Qt::Tool options are also relevant.
Be sure to check out: the ToolTip property of a QWidget and the WhatsThis property of QWidget.
http://qt-project.org/doc/qt-5/qwidget.html#toolTip-prop
http://qt-project.org/doc/qt-5/qwidget.html#whatsThis-prop
There are also other ways to make borderless, focusless windows that hover and disappear quickly on command. The Window Flags and Widget Attributes in Qt are very powerful when you are looking to modify Qt Widgets.
When you parent a Widget to another widget, it will draw itself on top of the other. Then you just need to resize and position it properly.
Also subclassing existing widgets can give you more options.
Draw text on scrollbar
Also common Qt::Tools that you will find are QDockWidgets. They are awesome!
Hope that helps.
Take a look at Qt Namespace especially Qt::WA_LayoutOnEntireRect and Qt::WA_StyleSheet. Pass it as a widget attrybutes. The second option looks promising but you have to create style sheet for QWidget.

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!