Need help on basic Qt structure - qt

Hi I am a Qt beginner. I want to make something like a column of icons on the left, after click the icons different forms and results appear on the right, how can I do this? Should I choose QMainWindow or QWidget for this project?

should I choose mainwindow or widget for this
project?
If what you described are the only things present in the window, you should use a QMainWindow. If you think you will want to re-use this arrangement in the future, I'd use a QWidget. It will probably be easier to implement each set of forms as a separate QWidget (in Designer; if you're building the GUI programmatically, just add the forms to a QLayout in a QFrame).
a column of icons on the left, after click the icons different
forms and results appear on the right
For the column of icons, you should look at QListWidget. It provides a vertical list of QListWidgetItems, and the items can contain icons, and nothing else. Your main window can then connect to the list widget's currentItemChanged signal (or itemChanged or something else; there are several choices), and modify the forms in the right-hand side of the window appropriately.

Related

Is there a way to create two independent layouts in Qt Designer?

I am new to Qt Designer so this question may be stupid but I'm really stucked.
I'm creating an app using Qt Designer and PyQt5. My app contains a few screens and I want to switch between them by clicking the button.
The first screen consists of a button (button_1) and a label (label_1) placed in a vertical layout. The second screen also consist of a button (button_2) and a label (label_2), but these are different widgets with different size and content. And I want to place button_2 and label_2 in a horizontal layout.
Previously I didn't use layouts. I just created one .ui file and put button_2 and label_2 above button_1 and label_1. They were overlapping but it didn't affect the performance because I made the button_2 and label_2 invisible when button_1 and label_1 are shown and vice versa. But now I need to make the window resizable, and I need to put the widgets in a layout.
The first thought was to create two separate .ui files and set them using loadUi command when it comes to switching between screens. But I need to use just one .ui file. Is this possible? How can I create two independent layouts? Or maybe there is another way to solve my proble. Any help is very much appreciated.
I think that in this case your best option is to use a QStackedWidget as a container for your labels and buttons. To create a stacked widget in Qt Designer you can drag a Stacked Widget from the container group on the left to the parent widget. This will create a stack with two pages. Each page can then be set up independently. Whatever layout you and widgets you add to a particular page will only be visible when that page is shown. You can add additional pages if you like by right-clicking on the stacked widget and selecting Insert Page from the context menu.
To navigate between the pages in Qt Designer you can choose the correct widget in the tree in the Object Inspector, use the two black arrows in the top-right corner of the stacked widget, or use the context menu of the stacked widget. To navigate between the pages in your python script you would need to use QStackedWidget.setCurrentIndex().

Qt desktop application

The Qt desktop application I am required to develop has the following GUI:
The application window is split into 3 parts -
left-side window - has a stack of clickable menu items one below the other. Clicking on each item will show up the corresponding UI elements on the prominent right-side window which is much bigger.
right-side window - contains UI to display some data depending on which menu item is clicked on the left-side window. Each left-side window menu item has a different corresponding right-side window UI.
top (header) window - contains some company "brand" related graphics and also a panel to select a serial port from a list along with graphics to represent connect/disconnect status.
How do I develop this kind of UI? What Qt classes should I be using? I'm a beginner to Qt and would deeply appreciate any help. Thank you.
I'd suggest starting in Qt Designer or Qt Creator to create your UI by dragging and dropping different kinds of objects. Qt Designer is a standalone form designer where Qt Creator is full development environment that also includes the functionality of Qt Designer. Using the form designer is a lot easier, particularly when starting out, than creating widgets programmatically.
There's multiple ways to do the list of items on the left. You can use a QListWidget or a series of individual QPushButton instances, one per option. If the list of items changes, then managing the QListWidget content is going to be easier than instantiating a QPushButton for each item, but you might like the appearance of the QPushButton better. It just depends on what you want.
For the right side, look into QStackedWidget. It's specifically designed to display a stack of content where only one item is available at a time.
For the top panel, again, use the form designer to create the layout. You can store an image in a QLabel. A QComboBox might be what you want for the list, or again, you may want a QListWidget. It just depends on what appearance and user experience you're looking for. For the connect/disconnect status, you can use a QLabel and change out the graphics as the status changes.
You'll need to learn about slots and signals; those are crucial to anything Qt-related.

How do I add a QWidget designed in Qt Designer inside a designed QMainWindow?

I started developing an application, I designed a empty QMainWindow wit just the menu bar. and created two new QWidgets and designed the features of my application on each.
Here is the thing: How do I add and interchange the last two QWidgets inside my QMainWindow?, so QMainWindow will show one set of features of my application at once.
Perhaps you are looking for QStackedWidget
(from Qt: The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.)
You can find it insde the Containers group
Add a StackedWidget into your MainWindow, then
Directly edit the widget at present page by Qt designer(use the upper-right arrows to switch between differetn widgets). Notice that
in StackedWidget you have to create another signal sender, ex: a
combobox to decide which widget should be shown), or
If your custom widget contains some customized and hand-crafted
funcationalites that Qt doesn't have, you might need the widget
promotion. (otherwise, skip this)

Drag and drop of QDockWidget between two or more windows

I would like to know if anybody knows if it is possible to drag a QDockWidget from one window to another.
I am developping an application that has a lot of windows. Each of these windows has a specific usage. I want to use QDockWidget because of the automatic rescaling when docking a widget in the main window. But I would also like to have the possibility to have a new dock area in a new window so that I can put together all the widgets related one to each other.
Does anyone have a suggestion?
As far as I know, you cannot drag a QDockWidget from one application to another if they are developed separately.
On the other hand, I think that you can reparent a QDockWidget to another QMainWindow, only if it's part of the same application.
...aaaaand you can always try to intercept the drap/drop events and pass information between the two windows with a protocol of your own: define a new mime type for the drag and define the syntax of the data associated to the QDockWidget. Then, implement the code to analyze the data and reconstruct the contents of the QDockWidget in the target window... not an easy task!

Qt: How to create a setting window like in GTK

In Qt 4.8 I want to create a window that looks like the following.
please note that my main concern is the tab-like behaviour of left-side icon+text combination.
The question is what would you recommend me to achieve that look? A QListWidget or a customized QTabWidget?
thanks
Qt Creator - which is written in Qt - has a settings page which might just be what you want:
I would look into the source code of that at http://qt.gitorious.org/qt-creator/qt-creator/trees/master
[Edit]
Found the relevant class here:
https://github.com/qt-creator/qt-creator/tree/master/src/plugins/coreplugin/dialogs
It is the class SettingsDialog. The GUI is setup in createGUI, they are not using an UI file actually.
This class is using a QListView on the left-hand side and a QStackedLayout with several QTabWidgets inside it on the right-hand side
I'd go with a QListWidget on the left connected to a QStackedWidget on the right.
Items in a QListWidget(View) can have icons on their left, selection can be exclusive (single selection) and when clicked emit signals which can change the current widget shown in the QStackedWidget.

Resources