Disabling restore down button in Qt MDIWindow - c++

Is there a way that I can disable the restore down buttons that appear at the top of the main window when I maximize my sub window in Qt?

I think you can use
QWidget::setWindowFlags( Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint )
There is an example in the Qt Docs called Window Flags (or something similar).

Related

Maximize and minimize buttons in an undocked QDockWidget

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.

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.

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:

Wrong window painting behaviour in frameless Qt window (win32)

I have an QML application (also tested it with QWidgets, same problem) and to make it borderless (but still support the native WM features like aero snap, etc) I followed this by implementing an QAbstractNativeEventFilter and responding to the WM_NCCALSIZE signal with zero:
switch(msg->message) {
case WM_NCCALCSIZE:
*r = 0;
return 1;
...
}
I also set some window flags which are not in the Qt Namespace with
SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME);
This works fine until I move or resize the window which causes Qt to rerender and a unpainted area width the width of the title and the borders appears:
Before moving/resizing
After moving/resizing
I also found a workaround for this by adding the FramelessWindowHint flag in Qt:
window->setFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::Dialog);
But now this margins occurs again when the window state changes (maximizing, minimizing, ...). By blocking the WM_SIZE event for example when SIZE_MAXIMIZED is the parameter the margin doesn't appear but then I also am not able to maximize the window from Qt. This means it is a Qt side problem.
I also noticed by inspecting the window style with winspector, that after I have maximized it a new property atom appears:
Can you help me fixing this?
I think using SetWindowLong on your window handle and using the Qt Window Flags/Qt Widget Attributes is asking for trouble. You can go and look at the Qt source to see what happens when processing those window flags.
When I've created frameless windows, I've usually done it to prevent moving and resizing, because I am managing all that separately.
One problem that I had related to it, was when the On Screen Keyboard came up and docked, it would resize my windows. So besides calling resize() I had to also use setFixedSize to prevent my widget from getting manipulated when the operating system attempted to change the size of the window.
So in other words, I would add an application wide QShortcut, listening for the snapping keyboard shortcuts and resize your window the way you want it to when it happens, if you are managing a frameless window.
Hope that helps.
I wonder if this was a flaw of Qt message relay, coz I met with a similar problem which occurs on nested windows. If you press SIZE_MAXIMIZE or SIZE_MINIMIZE button of the parent window, the child window sometimes is not able to receive WM_SIZE message. I suppose there are roughly two solutions: 1. Fix Qt, 2. Work it around.
Here I have a OGL rendering child window, sometimes even the WM_SIZE message is not correctly passed. That is, if you resize parent window, you get part of the client area black.
I just use a simple workaround to fix this, which check the current size with the cached one, and make a sort of manually resize myself.

Create a desktop widget (like Yahoo Widgets or Google Gadgets) with Qt 4

How do I create with Qt 4 a window that remains anchored to the desktop as a widget ?
(e.g. like Yahoo Widgets or Google Gadgets).
I intend to give the same characteristics of a widget to a normal window:
Remove the edges (easy to do)
The window must not move (how ?)
Must be displayed only when other windows are minimized (how ?)
I think setting these flags will do what you are looking for:
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint);
Remove the edges ---> Qt::FramelessWindowHint will remove the edges
The window must not move ---> (AFAIK) you can't move window when Qt::FramelessWindowHint flag is set
Must be displayed only when other windows are minimized ---> Qt::WindowStaysOnBottomHint will keep the application window below all other windows
I don't think Qt provides anything specific to do this. You will need to create and manage your own window but you can use QDesktopWidget to help.