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:
Related
I´ve been trying to add the buttons to an undocked QDockWidget window as I normally do for a QDialog, but with no success as follows:
QDockWidget* dw = new QDockWidget(QString("Stream %1").arg(i + 1), this);
dw->setWindowFlags((dw->windowFlags() | Qt::WindowMaximizeButtonHint |
Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint));
When I undock them they still only have the [X] close button.
What am I missing?
Development environment info:
Windows 10 x64,
Visual Studio 2015,
Qt 5.7.1,
C++
I figured out how to do it. You have to connect to the QDockWidget toplevelChanged(bool) signal.
connect(ui.dockWidget, SIGNAL(topLevelChanged(bool)), this, SLOT(dockWidget_topLevelChanged(bool)));
Then you need to check if its floating and set the window hints.
void MyClass::dockWidget_topLevelChanged(bool)
{
QDockWidget* dw = static_cast<QDockWidget*>(QObject::sender());
if (dw->isFloating())
{
dw->setWindowFlags(Qt::CustomizeWindowHint |
Qt::Window | Qt::WindowMinimizeButtonHint |
Qt::WindowMaximizeButtonHint |
Qt::WindowCloseButtonHint);
dw->show();
}
}
I'm afraid you can't do it that way, as QDockWidget look and feel is essentially hard coded in the QStyle your application is using, as stated in the documnetation (here in the "Appearance" section). Basically, QDockWidget is a borderless window, and the title bar and its structure(title, buttons, etc) is just painted using the style.
To overcome this, you may use a QProxyStyle to paint the minimize and maximize buttons, but these would not be "real" buttons but just their pixmaps. Hence, you would still need to perform some tinkering to handle the clicks to those virtual buttons (e.g. catching the click event on the title bar and determining if it happened inside one of these buttons).
Another possible solution is to subclass QDockWidget and implement all the painting and click event handling there. Beaware that if you want to support multiple platforms you may need to use QStyle::drawControl() to paint the extra buttons, instead of painting everything by yourself (e.g. drawing a pixmap).
I hope this helps you. Good luck with your project.
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.
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.
On Mac there is a window flag/call: WindowTitleHidden + [nativeWindow setTitlebarAppearsTransparent:YES]
which basically makes the title bar to be "embedded" inside the window itself instead of creating a frame that "holds" the window. Like this:
Notice how the minimize, maximize and close buttons are on the same row as the app's widgets.
Is there something similar for Windows?
Like this:
Code: https://github.com/alexandernst/TrueFramelessWindow
AFAIK, you must draw them yourself and then reply to the WM_NCHITTEST mesage that Windows sends to your form to query where the mouse is positioned. That way you can tell Windows that the mouse is located over a, say, maximize button, although Windows itself didn't draw one there.
The painting can be done with the help of VisualStyleRenderer or ControlPaint.
I hope these questions will point you further:
Winforms: Add a close "x" button in a UserControl
Winforms - WM_NCHITEST message for click on control
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.