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.
Related
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.
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
The qt designer portion of qt creator has many built in widgets. But let's say I want to add custom widgets created in the same qt project to the ui file of the window. By taking these steps:
Create a new Qt GUI application with a main window, we'll call the window A.
Add a new widget to the project, the widget just uses standard UI components, say buttons. We'll call this widget B.
Add an instance of widget B to window A.
Now, I know one way to do that, and that is:
In window A, add a blank widget (or widget container, from the containers section of the list of possible widgets. We'll call this widget C.
Promote it (widget C) to widget B.
However, the problem with this is that Qt Creator's designer treats it like a generic QWidget. And as such, you can't do things like add it to a splitter, or connect signals/slots that are specific to the widget.
So is there any other ways to add widget B to window A in the ui file using qt creator? Thank you.
I'm not sure to understood your question well so I could ask the wrong question. Are you sure your "B" widget is a subclass of QDesignerCustomWidgetInterface? This should expose all stuff that your widget/plugin offers...
Last note: a friend of mine tried to add a custom widget like you. And at the end of the described procedure that Lol4t0 told you, he found you must compile plugin with the same compiler with wich qtcreator/designer was compiled. This happens because as we know c++ doesn't keep ABI compability (instead of i.e. C language) stuff like: Name handling can change from compiler to compiler, how data is loaded into registers can change...and so on. My friend tried to compile plugin with mingw, but he found that qtcreator was compiled with visual studio compiler. Therefore if you want to deploy your plugin on Windows or you compile your plugin with visual studio, or you have to compile qtcreator/designer from scratch.
I know this is a very old question, and I'm not sure what capabilities Designer had in 2012, but I came across this in a Google search for something else and figured I'd add some missing info:
However, the problem with this is that Qt Creator's designer treats it like a generic QWidget. And as such, you can't do things like add it to a splitter, or connect signals/slots that are specific to the widget.
Generic QWidgets can be added to splitters with no issues these days.
As far as signals and slots go, you can use them like so:
After promoting a widget to your custom widget, right-click it and choose "Change signals/slots..." from the context menu.
Add the signatures for any custom signals and slots you want to be able to use in Designer / Creator here.
Now those signals and slots will be accessible in Designer like any other signals and slots.
The only thing you can't really get with promoted widgets is access to custom properties in the property panel; for that, yeah, you'll need to go through the custom widget creation process.
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.
Im just pondering best practice with an application I'm developing. Its a simple one window application using qt creator. It's just going to start a QProcess and show the output in a QTextEdit box. To do this there needs to be a bit of processing between the output of the QProcess and the QTextEdit but i dont know where i should do this, should i create a new class to do that or add member functions and extra signals and slots to my main window? I dont want mainwindow to become bloated and hard to read but equally i dont want to have more source files than really I need.
Any thoughts?
The main window class can very easily get bloated with all kinds of functionality. I've dealt with that myself, so it's a very real trouble.
Really, though, this is not so much of QT question as it is an object-oriented design question. The key is that your output window does not need to be a part of QMainWindow, so it probably shouldn't be. Make the display a widget, and insert it onto the main window. That is much more flexible, as if you ever need to move that output pane for any reason, it won't be coupled to a specific part of the program.
The logic that feeds data into that output pane should also get its own class, separating the responsibility for displaying the output from the responsibility for acquiring the output.
For reference on the concepts behind my suggestion, see the Single Responsibility Principle and the separation of concerns.
Also - you may wish to have a read at this link to model view delegate information which is how I tend to develop in Qt. Like the person above says - this is more a question of good OO design.