Equivalent of WinForm "Dock Fill" for Qt Widgets / Layouts? - c++

Starting with Qt (coming from C#, WinForms) I wonder what the equivalent of Dock: Fill is (a control shall use all available space)?
The screenshots below show the structure of my simple demo application. The QTableView shall expand to the full horizontal dimensions. In a WinForm I'd accomplish this by using Dock: Fill. Is there a (similar) solution in Qt?
I have tried the SizePolicy and LayoutSizeRestriction (SetMaximumSize), but with no success.

It can be a little unintuitive the first time around but you just need to set a layout on the QDialog. Right-click anywhere on the dialog form and select "Lay out".

Related

Nested comboboxes in Qt

I'm looking for a way of nesting comboboxes in my GUI application (or to be more precise, I'm looking for a way to have an item displaying similar visual and functionnal properties as nested comboboxes).
Looking first at all the functions provided by the combobox class, it seems comboboxes nesting it's not supported by Qt.
I therefore thought that another solution would be to create a "menu" item outside the menu bar. If I understand correctly this phrase from the offical Qt documentation, it seems to be feasiable :
A menu widget can be either a pull-down menu in a menu bar or a standalone context menu
Not sure though was is meant by the "context" word.
However, there is no such (menu) widget in Qt designer and I haven't found any good examples about how to do it on the internet (and can't get a menu not associated with a menu bar to be displayed on the windows), explaining why I'm currently doubting whether it's feasible or not with a menu item.
I would greaty appreciate if you could provide some code sample along your response.
EDIT :
To clarify my first post, I'm trying to do something similar to this app :
It's the application that comes along the 3D connexion mouse whose usage is to parametrize each button.
As you can see, there are several sub-menu items. By clicking on the arrow next to a textbox, you open a sub-menu containing itself folders that contains themselves paramaters.

Qt - What should I use to implement multiple windows?

I've started learning Qt (C++) and I'm overwhelmed by the whole lot of component it has. I'm writing my first application and here's what it should look like:
When I run it, I have one main widget which has 8 QPushButtons.
When I click any of the buttons a 'window' should open and it should
contain about 25-40 various labels, buttons, checkboxes, radio
buttons and so on. So, I need 8 'windows'.
My question is: what should I use to implement these 'windows' - Widgets, Dialogs, MainWindows? What is like a conventional QT way of solving this problem?
It depends on how you want your application to look like.
If you want to have multible 'Windows' like different Tabs in your application then use QStackedWidget Class or QTabWidget Class.
If you need something like a Pop-Up you could use a QDialog.
Please make sure you understand how QWidget works and always take a look in the Qt Documentation.

Creating a listbox-like control in QT C++

I am a beginner at QT and I have been trying to port a GUI project over from raw Win32 to QT. Only problem is I cannot find the name for some controls in the QT framework such as the pictured one below.
I believe it is called a listbox in C# and C++ and I used some code to put the title bar up at the top containing "Update, Version, Size, Date". What would this translate to in QT? I have tried the tableview from QT but it only succeeds in making a Microsoft Excel type box with rows and columns, my goal is only to get vertical columns with a title at the top. Thank you!
That's not a ListBox control, that's a ListView control.
Not sure what Qt calls it, but since they prefix everything with a Q, I'd imagine it's QListView.
The ListView is like a super-duper ListBox that also has a column header attached to it when you set it to display in "Details" view.
QListBox was deprecated in Qt 4, and was replaced by QListView.
For the type of multi-column control pictured, QTreeWidget should work.

Making a game in Qt regarding GUI windows

I've been wanting to program a simple game with a simple GUI using Qt (Its will be a VERY simple game, nothing fancy). What I've been wondering is, how can I create multiple windows and display them when needed? For an example, a battle screen and an inventory screen. The user should only see one of them, but should be able to access the other one when needed. I was using stacked widget but I'm not sure if that's the proper way. Also, is it better to design the windows in the designer or to code them?
A StackWidget certainly would accomplish what you want to do. The reason why it is not always used for this kind of thing, is that it all the screens are pre-created at the beginning and always exist. This means it takes a little longer to initialize, and you are using more resources than you need at any one time
But as you are saying, if this is a simple game, then I don't see a big problem with it. Just as easily, you could also, create an empty layout and swap the inventory and game panels as needed.
Add my vote to everyone else suggesting to use the designer. It is so much easier to manipulate layouts, actions, and such using the designer then through code.
You can see the Designer manual here
So this is what I would suggest:
Create your "battleScreen.ui" - which is the designer file for your battle screen and everything in it, and then create your "inventory.ui". Both of these could be QWidgets, or QFrames, or whatever makes sense.
Then create your "Game.ui" which will be your QMainWindow.
In your Game main window, you can then add your QStackWidget, and place your inventory, and battle screens in the stack widget.
If you don't know how to do that...
1) drag a QWidget into your form (into the stack widget)
2) select the new QWidget and right-click.
3) Select "Promote to..."
4) Fill out the information to promote the QWidget to your inventory class
Promoted Class Name: The name of your inventory class
Header File: The header file of your inventory class
5) Click add
6) Click Promote.
Hope that helps.
Since I'm not sure what your goals are I can't advise whether or not the stacked widget is appropriate but I think you can accomplish quite a lot using the designer and style sheets. If you need to code some parts of the GUI, you can always drop in a place holder widget and either replace it with coded items or make them children of the place holders.
A general answer for a general question:
Use the Designer to create your windows; hide and show the auxiliary windows as needed.
Use a flow manager class to manage the visibility of a related set of windows.
The stacked widget is useful for managing a button/icon whose appearance changes based on state; the different representations live in the stack.

Qt: How to show icon when item selected

I have a QListWidget containing items which have icons and when the items are selected the icon is just highlighted out. Is there a way to prevent this? I can't use stylesheets because it's for an embedded application and including them takes up too much space.
thanks
I suppose when you say "Highlithed out", you mean that the icon colors don't render well when the line is selected, and therefore, you can't see properly the icon...
Maybe you could consider using a different icon when the item is selected. It's possible to do so by specifing a mode to your icon.
Example :
QIcon MyIcon(":/images/foo");
MyIcon.addFile(":/images/bar", QSize(...), QIcon::Selected);
You can easily make a try in QtDesigner and see the results...
Hope it helps a bit !
Certainly, drawing on a black-and-white screen presents its challenges.
It sounds like you just want to change the appearance of the interface, not any functionality. If this is the case, a QItemDelegate-derived class (or QStyledItemDelegate) is almost certainly what you want. In particular, the drawDecoration function looks like it is used to draw an icon, and the style options should include whether it is selected. The simplest fix would be to override that function, set the selected flag in the options to false, then pass it up to the parent's function.