Best approach for building a dynamic widget perspective using QT? - qt

I am building an interface similar in features to the Eclipse IDE for a telemetry project. I'll be showing many different widgets and each of them needs to be resizable / moveable / popped_out / popped_in / hideable / "fullscreen-able" / etc... like a "perspective" of the Eclipse IDE.
What would be the best approach using QT? Which classes to use? Using QT's QMainWindow / QDockWidgets / LayoutManager or since any widget can be moved anywhere would it be best to handle everything by hand-coding ?

In my opinion, QMainWindow gives you a good start. You can create and manage DockWidgets all around your central widget and add status and tool bars fairly easily.
The QDockWidget class already handles the dock/undock hide/show options, so all you have to do is do your own widget.
Also, if you want widgets to be hideables, you could look into QSplitter that allows to show two widgets, one on either side and resize them. They are collapsibles by default.
Hope this helps.
EDIT (to answer the comment question):
You can use QSettings to do so. It allows you to save any settings you want in the system directory.
You do so like this:
QSettings settings;
settings.setValue("editor/wrapMargin", 68);
and to get it back:
int margin = settings.value("editor/wrapMargin").toInt();
Hope this helps.

Related

How can I create a system similar to QDockWidget but for tabs?

I had an idea I have no clue on how to implement. I'm working with Qt and I'ld like to have a system of tabs that allows me to use tabs in the same way one can use QDockWidgets, that is: with QDockWidgets one can pick a widget and use it floating around the monitor or he can dock it in a QMainWindow in any of the four sides. Well I would like to have such attribute with a QTabWidget! So suppose I have two QTabWidgets in front of me. With the proposed idea, I would be capable to drag and drop a tab (with its widget) from one QTabWidget to another or even simply undock it from its original QTabWidget and start using it independently as another QTabWidget with one tab.
Well I couldn't find a way to use QTabWidget this way "naturally"; it seems Qt doesn't provide such possibility with its pack of widget classes. So does anybody knows any project open to the public containing a class able to do such thing? Or how could I implement such a new class myself? (I don't know for example how could I make the drag and drop effect from a QTabBar since even if setMovable is set to true, still isn't possible to make the tab go away from area of the QTabBar.
Any help will be appreciated.
QDockWidgets already provide possibility to be tabbed.
You can check Dock Widgets Qt sample project in Main Windows section.
Screen of the just launched sample app:
Screen of the tabbed doc widgets:
Check this answer for implementation details.

How to programmatically add a UI to a widget based on a Qtvtkwidget?

I am trying to write a program based of of this example i.e. a widget based on QVTKWidget, so that I can use the PCL Visualizer inside the widget, with no UI and the first step for me would be to add a simple UI a menubar with some simple options: close,save etc.
Unfortunately my experience with QT interfaces is with the Designer, I have though seen what ui files look like but I have seen no tutorials on how to add them to widgets, tutorials for adding them to main windows I've seen a few.
Do you know of a simple method to add a .ui file to a QVTKWidget or a widget in general?
The easiest way to do this is to create an application, or a widget in designer, then add a plain QWidget into the content, this QWidget you promote to type QVTKWidget, through the designer interface as described in the documentation. Then you can add all the other ui elements to the application and interact with the QVTKWidget

Sidepanel with Qt

I'd like to implement a sidepanel in my Qt window. I search something like the one that is used in the Visual Studio (see below).
Important notes:
The widgets don't have to be moveable
resizing should be possible
each widget should be clearly separated from the other layout
Does anyone have an idea how I could build such a sidepanel? (Maybe there even exists a library)
Or does anyone know a project which uses Qt and some kind of sidepanel?
One option would be to use QDockWidgets. That's the type of thing they are intended for inside a QMainWindow.
You can put toolbars, QTreeViews and QTableViews (or related) widgets inside your dock widget to simulate the screenshot you posted.
For an example usage: Dock Widgets Example.

Base class in Qt Creator 4

I am new to Qt Creator 4. When I create a new project it gives me the option to choose a base class:
QWidget
QMainWindow
QDialog
I am confused which to choose. What difference does it make?
Does it also effect the code?
Kindly explain in simple words.
QDialog is specifically designed for dialog or "pop-up" windows. These are dialogs generated from your main application, useful for things like Open/Save dialogs or informational messages.
QMainWindow is a specific widget that has things like a menu bar, tool bar and status bar built-in. This class is useful for the main application window to fit around your main UI.
QWidget is the base of every GUI element, so it's a catch-all. It's less specific than the other two classes, but in exchange it's more flexible.
You should choose the one that best fits what you are creating. Obviously the way you write the code will be effected, as they are different classes, but all are still QWidgets.

Classes to use for a flexible image selection/tagging widget in Qt

I'm new with Qt and am looking for advice on how to structure this.
I want a flexible widget that can display a set of images (normally read from a directory but other sources too) and let the user select images with the arrow keys and/or mouse and also apply custom tags.
For example there might be 5 tags defined by the application. A user can press a key to select one, and then a little icon would appear in or near the image preview showing that it was selected for that tag.
Would I need to implement this from scratch via drawing on a QWidget or is there something that would make a sensible base class? Thanks!
I would use a QListView base class, and then subclass QStyledItemDelegate.
There is an example here which might help you.

Resources