I don't know much about QT. I am trying to do my first GUI and actually this is the first thing that I want to do.
How can I set up top menu bar to switch between layouts? Again, I don't know yet how to even set up these layouts and I don't know the jargon to name the things theirs names, but I'll get to it.. I hope.
Actually, Windows has this type of windows all over the system. Can I make one of these myself?
Qt has a QtabWidget that has its own layout on every tab, so you dont need to define anything, qt handle t runtime the display of the layout associated to every tab
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'm using qt 4.8.0 on windows 7.
When I open qt designer and create widget in it, I cannot set 'Lay Out in a vertical/horizontal in Splitter'. Also there is no Splitter in a Layouts widget box.
All other layouts are working well.
Have anyone run into same or similar problem?
You need to select two or more widgets and then use the layout -> vertical/horizontal splitter option. This will give designer enough context to be able to perform the operation.
Also note that the selected widgets cannot be part of a layout already. If they are, you need to break the layout first (layout->Break Layout in context menu).
It's in the contextual menu that appears on right-click in the body of the widget.
You can establish the widget's layout including splitter there.
EDIT: Sorry, I misunderstood in a rapid first-reading. Are you saying it doesn't appear in the right-click menu, between the other layout options?
I plan to use a spacer in my toolbar (below) between the 'Pause' and 'Settings' buttons to make the 'Settings' button right-aligned within the QToolBar. The separator below isn't cutting it.
The following method apparently works, although I haven't actually tried it yet:
QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// toolBar is a pointer to an existing toolbar
toolBar->addWidget(spacer);
toolBar->addAction("Right-aligned button");
(thanks to http://www.ffuts.org/blog/right-aligning-a-button-in-a-qtoolbar/)
Qt Designer doesn't seem to allow adding widgets to a QToolBar, although QToolBar does have an addWidget() method, as used above. So if I want to be able to add the spacer to my toolbar using Qt Designer (with a plugin, not promotion), should I subclass QAction, QWidget, or QWidgetAction? Is there even a way to write custom action plugins for Qt Designer?
You cannot subclass QAction and expect to use it gracefully in Qt Creator/Designer. It uses the tags in the ui and to add them to menus and toolbars. You can't specify a class="customclass" element along with a entry like other widgets. Because actions are treated differently, you cant even subclass them so that's out.
As for QWidgetAction/QWidget, you are in the same boat as QActionGroup, if you know what I mean.
(I personally think this is a big overlook in the design of the form designer!) So previewing that in the designer is also out.
The last thing you could do (invisible option 3) is QToolbar subclassing, but alas you can subclass it, but still, you wont be seeing anything in the desinger other than what a plain old QToolbar can do. That doesnt mean that it is completely out which is the point I'm coming to:
The real answer would have to be invisible option 4, subclassing QToolbar as a designer plugin (which would require a lot of coding on your part if you dont already know of one that is out there, I dont know of any that actually have designer plug-ins) Form Designer plugins are more not than often, but you could find someone's subclassed toolbar, and make it into a plugin yourself saving you a step (qt creator even has a template for that), then use it in qt designer and your set.
I know this question got asked 2 years ago but when I see an unanswered question, I think of those searchers that might read and get frustrated by a dead-end so if I can contribute I do... I hope I did at least help you or anyone else get on the right track, and good luck to you all!
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.
I wanted to consult with the sages here regarding Qt and skinning, get your opinion and chart a path for my development. My requirements are as follows:
My Qt/C++ application (cross platform with Mac, Windows and Linux versions) needs to have modular skins.
A skin is defined as a set of one or more elements: - Window background texture - Look/feel of UI controls such as edit boxes, drop down, radio buttons, buttons etc. - Look/feel of window "caption", resize grips etc.
Skins will be installed with the application installer, allowing the user to choose which one he/she wants to use. Users should be able to change skins on the fly.
Can I go the QML route? should this be custom and based on simple resources which are built into the application? Any design advice will be appreciated.
Thanks.
If I understood you correctly then stylesheet is the best way forward. You can create stylesheets similar to CSS and then pass them as command line option to your application or load on invocation to style your application at runtime. That way you can create multiple stylesheets each having a different look and feel and allow user to load them at will. Since its CSS it doesn't need any new learning and you can keep all your styling outside your source code.
Here are a list of resources that can get you up and running quickly:
http://blog.qt.io/blog/2007/11/27/theming-qt-for-fun-and-profit/
http://doc.qt.io/qt-5/stylesheet.html
I haven't played with QML yet, but you could also create a custom QStyle implementation that supports your resource format. Note that you'd lose style sheet support if you went this route.
Changing window captions is a little trickier if you want portability.
QML, if I understand correctly, doesn't really skin the widgets, it mainly deals with GUI layout etc etc.
QStyle is used to change the looks. It is a bit low-level though, and requires programming, so if you want to load different user-created skins (from an XML or so) it might be tricky to support extensive skinning. Chaining colors and a few items are easy enough though. (There might be someone else who've done something you could re-use.. not sure.)
For modifying widgets, use QStyle::polish(). You could use that to change the background picture (if it's a top-level window, or of a certain class). There are numerous repaint method to change almost every part of every widget.
Store/load the style using QSettings, by reading and setting the desired Style just after QApplication but before your main window is constructed.