Qt Ui Designer - creating window default frame and default buttons - c++

when I create a window with the Ui Designer in QtCreator, most default templates give me a somewhat blank grey frame. There are options for adding more frames like that on the inside, but how do I add the default blue ribbon on the top with the window title, icon, minimize, maximize and close buttons? There is no option for that anywhere.

Generally, you don't - that's up to the operating system.
You can preview the window style with various skins in creator - select the skin under tools->options->designer->forms, check Print/Preview Configuration and there are various options for Style and device skins.
There are some options regarding window style under QMainWindow as well, for instance unifiedTitleAndToolBarOnMac, but it is best to leave the outer window to the OS.

Related

How to use my custom minimize/close window buttons in my QMainWindow?

I would like to remove the windows title bar (and minimize/maximize/close buttons) of my QMainWindow. And I would like to use my own minimize/close buttons.
I know how to remove minimize/maximize/close window buttons. It's not a problem.
How to remove the window border (containing minimize, maximize and close buttons) from a Qt widget?
The problem is to add those new buttons (minimize/close). Is it possible to do that in Qt Style Sheet (or in C++) ?
ps: I would like something portable for Windows/Mac/Linux
Unfortunately that kind of decoration depends on the windows manager. You may find OS dependant solutions (this for Windows changes other aspects of the title bar, for example), but if you remove the window buttons, then the only portable option I know is to create your own container window, a QWidget that has a header region with the buttons you want and a centralWiget where you can add the rest of you application:
You then connect header buttons
connect(m_ui.btnMinimize, SIGNAL(clicked()), SLOT(showMinimized()));
connect(m_ui.btnClose, SIGNAL(clicked()), SLOT(close()));
To make it reusable, just add an insert(QWidget*) method to replace the centralWidget.
Note: take into consideration that you must create the container with the Qt::FramelessWindowHint flag set, therefore if you want to allow the user to move/resize the window, you must take care of those actions manually too.
You should create window without system bar (without minimize, full-screen, close buttons you can use the next flags for that Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint) and add your own customized system buttons.

Close button on QTabWidget not the Tabs in the QTabWidget

I am using Qt-5.8 over Ubuntu.
This is how my QTabWidget appears :
And the black dot is where I want the Minimize Button to happen.
One way I came across is that I can use QToolButton *qToolButton to create a new button and tabWidget->setCornerWidget(qToolButton) and then add the implementation over its click event.
But should there not be any other way to just show the minimize button as like in MainWindow or SubWindows has. Which just minimizes it.
Minimize button on top panel of your QMainWindow's instance is part of Windows Manager subsystem of your OS. So you can't use similar approach inside your window as toolbox with buttons, etc.
As you wrote, try to use tabWidget->setCornerWidget(qToolButton) to place your custom minimize button inside your window.

How to dock horizontally Qt widgets?

I am migrating to Qt from Microsoft Visual Studio. Common design for dialog boxes in desktop applications is set of labels and fields, where dialog looks like grid with labels and related fields. So, we can have Username label and text box to the right from that label, then Password label, etc. Usually when we resize a window, label size remains fixed, and text box width is increased to fill extra space, so user has more space to enter long string in text box and see it without scrolling.
Visual Studio has docking concept to describe such layouts, so you select a control and set its resizing behavior, in our example we have to set Dock = Fill for text boxes to instruct Windows Forms how to resize them. WPF has similar functionality if you set Width = *.
However, I don't see any such properties in Qt Creator Designer.
So how to instruct Qt widget (text box for example) to fill all space available in its parent widget?
In Qt, widget geometry can be automatically managed by layouts. A widget by itself won't fill the parent. You need to set a layout on the parent widget, and add the widget to the parent. There are numerous tutorials on that.
The particular layout that would apply to your situation is QFormLayout. This answer has a complete example.

QT: Frameless window not animating

i need some help for my current project named "RibbonUI".
As the project name suggest, i want to implement the MS RibbonUI like in Office 2013 in QT - most stuff is working nice but i need to know something about the Qt::FramelessWindowHint.
I have subclassed the QMainWindow and added the enum value Qt::FramelessWindowHint to override the default window decoration. The buttons are implemented fine - i can minimize, maximize and close my frameless window, but the window is not animated when minimizing/maximizing/restore the window from the taskbar.
Do i have to implement the animation by myself or can i use a window manager hint or something else?
Here is a screenshot from my current work:

Setting and manipulating Icons in QT

I want to add icons in QMainWindow and when i will click that window it should perform some action like popup some window. So what should i use for the icon menu?
You could use the QToolButton class to accomplish this task.
It is possible to set it to only contain an image/icon without text.
l buttons are normally created when new QAction instances are created with QToolBar::addAction() or existing actions are added to a toolbar with QToolBar::addAction(). It is also possible to construct tool buttons in the same way as any other widget, and arrange them alongside other widgets in layouts.
A tool button's icon is set as QIcon. This makes it possible to specify different pixmaps for the disabled and active state. The disabled pixmap is used when the button's functionality is not available. The active pixmap is displayed when the button is auto-raised because the mouse pointer is hovering over it.
The button's look and dimension is adjustable with setToolButtonStyle() and setIconSize(). When used inside a QToolBar in a QMainWindow, the button automatically adjusts to QMainWindow's settings (see QMainWindow::setToolButtonStyle() and QMainWindow::setIconSize()). Instead of an icon, a tool button can also display an arrow symbol, specified with arrowType.
So, you would use these methods:
QAction * QToolBar::addAction(const QIcon & icon, const QString & text)
Creates a new action with the given icon and text. This action is added to the end of the toolbar.
and
toolButtonStyle : Qt::ToolButtonStyle
This property holds whether the tool button displays an icon only, text only, or text beside/below the icon.
The default is Qt::ToolButtonIconOnly.
To have the style of toolbuttons follow the system settings (as available in GNOME and KDE desktop environments), set this property to Qt::ToolButtonFollowStyle.
QToolButton automatically connects this slot to the relevant signal in the QMainWindow in which is resides.
As you can see, the default is icon only.