Qt QDockWidget(floating) minimizes when my MainWindow minimizes - c++

How can I minimize my QMainWindow without also minimizing my QDockWidget that I have undocked and is floating? What I want to do, is take a small window of my GUI to monitor the rest of the MainWindow. The MainWindow does not to be on the screen, all I want to see is the DockWidget while it is floating.

The floating window is almost certainly being minimized when your main window is minimized because the main window owns the child window. Or in other words, the floating window is a child of the main window. And a child window cannot be visible when its owner window is minimized.
The solution obviously is to break the ownership relationship between your floating window and the main window. That will probably also require that you change the type of window that your floating window represents. I'm guessing that a QDockWidget class implements a floating tool palette or other form of pop-up window. In order to have a standalone window, you'll need to create an overlapped window.
Read more about the various types of windows here, at least assuming that you're using Windows.
I imagine that it's a similar state of affairs for the other target operating systems.
On Windows in particular, someone might suggest that you make the floating window a child of the desktop window, but let me take this opportunity to strongly advise you against doing that. For a more nuanced discussion, see Raymond Chen's blog post on the subject.

A floating QDockWidget is automatically minimized when its parent QMainWindow is minimized. There is nothing you can do about that. You may have to change your QDockWidget into a QDialog (or some other QWidget) with parent = 0.

Related

How to change UI without opening a new window in Qt?

In my program, I'm moving from QMainWindow to QDialog on a press of a button.
I want to do the same without opening a new window and be able to move between the UI's.
The Target device will have a very small touchscreen, so I want my UI to sit still and require minimal repositioning.
Please point me in the right direction or give me an example on How-to.
To do that, you can use a QStackedWidget.
From the documentation:
The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.
Instead of opening a new window, push its content on top of the stack and pop it when you want to (let me say) close the window.
Each widget is a page of your application and no separate window is required. You can design them as you would design a central widget of a normal window or dialog.

How to minimize a frameless window which has been set size to fixed by method setFixedSize in Qt?

How to minimize a frameless window which has been set size to fixed by method setFixedSize in Qt?
Hi,
I'm using C++ code to make a Qt application. I set the window to frameless by
this->setWindowFlags(Qt::FramelessWindowHint);
So I can't click the minimize button support by Operating System and I made a customed one. But, when I want to use
this.showMinimized();
I found that it can't work with window which has been set fixed size by
this.setFixedSize(width, height);
So my question is, is there some other ways to make the window minimized which can be used by a window that set fixed size?
This is almost definitely not what you are looking for, but most if not all modern operating systems contain a minimize-all keyboard shortcut or show desktop button. You may have the button on your task bar, if you have one. If not, try windows-key+d or control-alt-d. If you want to learn about how to minimize a qt window from within your code(what I think you probably want), I recommend you check out the surprisingly clear documentation at doc.qt.io.

A child widget is transparent to events when parent is set after child creation

I have a qt application that is comprised of a main window and a settings window that I am trying to port to Qt5.
I use QWidget::setParent() to set my settings window exactly on top of(and cover) my main window, and prior to using qt5.1.1 (the previous version I used was qt 4.8.5) this method worked fine.
The problem I have right now is that the settings window is being displayed correctly but almost all mouse events(minus the mouse over on some of the buttons) are being passed directly to the main window which is underneath.
I have tried setting different flags for the settings window to no effect.
This issue does not reproduce on windows.
I've being searching for a solution to this problem for some time now.
I am using qt 5.1.1 on MacOSX 10.7.5
Your problem is with overlapping siblings. When you reparent the settings window, it has various siblings inside of the main window that overlap it. This seems to have undefined behavior, as you've just learned. Your window is not added to any layout merely by being reparented. If it was added to the layout (except for stacked layouts), you wouldn't have this problem, and of course it wouldn't look right either.
A portable solution would involve using either:
A QStackedLayout as the base layout within the main window. Note that this won't work for QMainWindow, QScrollArea and similar windows that don't have container layouts applied directly.
A QStackedWidget as the base widget class, with your QMainWindow or similar class inserted into it.
In both cases, you temporarily insert your settings window into the stack, and flip the pages.
Note that this behavior is questionable from user experience perspective.

MFC: How does a FrameWnd know when a docked pane is resized?

I have a CFrameWndEx with several docked CDockablePanes but I can't seem to get notified when the size of the docked pane is changed (so I can resize my other windows accordingly). Tried Spy++ to check for messages, but custom draw seems to be the only one (which doesn't seem appropriate) and also tried overriding RecalcLayout, but that is not called under this circumstance. OnSize doesn't work because the size of the frame itself is not changed. Any ideas?
(Ps: I'm pretty sure it's possible because I used to have a splitter window as the 'client' area, and it would resize itself magically when the panes were resized)
OK this is a bit weird, but I had the exact same question, searched on Google, then saw that I had answered this question over a year ago but completely misunderstood what the question was about :)
Anyway for reference of future Google using people, the answer to this question is to override virtual void CFrameWndEx::EAdjustDockingLayout(HDWP hdwp) and do any resizing of client controls there. To get the client area after the hiding/closing/whatever of panes, use m_dockManager.GetClientAreaBounds(). My AdjustDockingLayout looks like this (m_View is the child window that is supposed to fill the whole client area regardless of the state of any docking panes, adjust as needed):
void CMainFrame::AdjustDockingLayout(HDWP hdwp)
{
CFrameWndEx::AdjustDockingLayout(hdwp);
if (m_View.GetSafeHwnd()) {
CRect rectUsable = m_dockManager.GetClientAreaBounds();
m_View.MoveWindow(rectUsable);
}
}
I think the issue is that the 'content' of the CFrameWndEx is itself a window, and in that window live the 'main content' windows. Check with Spy++ for the window hierarchy and if any of the child windows of the CFrameWndEx (other than the dockable panes) do get message when they are resized. Basically when docking panes are docked, the CFrameWndEx resizes its children, so you'd have to detect it there and (if required) reflect the message back to the CFrameWndEx if that's really where you need it.
Alternatively, maybe I'm misunderstanding and is what I described exactly what you're trying to do. In that case, I think there is something wrong with the way you add your window to the CFrameWndEx since that should handle the resizing itself. Is the parent of the child window set correctly to the CFrameWndEx when you create it?

Qt - What exactly is QWidget

In the C++ GUI Programming with Qt 4 book, it mentions in an example in the first chapter that QWidget serves as the application's main window.
And, on the Qt Reference Documentation: http://doc.qt.io/qt-4.8/qwidget.html there is plenty of information about QWidget.
But, what is the baseline? What does QWidget mainly do? When should I think about it?
One way to think about it is any object that knows how to display itself on the screen is a QWidget (in particular, some subclass of QWidget).
There are some objects like QPicture that represent an image, but a QPicture by itself doesn't know how to put itself on the screen. You usually need to use it in combination with a QLabel for instance (which is a kind of QWidget).
It is an abstract of window objects. Every visible/invisible Qt window-related object inherits from QWidget.
Just consider a vehicle, it is the abstract of cars, trucks and other stuffs.
Widget is X11 parlance for something a bit more generic that what other systems call a control. A widget can be a pushbutton, a listview, a window, etc...
And BTW, it supposedly comes from Window Gadget.
In windowing systems like X11, there is no difference between a toplevel window and a widget. All are called "windows", and all of them have a parent and children (except the root window, which is usually what the desktop wallpaper is drawn on). So it makes sense that a widget can either be a toplevel window (i.e. a child of the root window) or any other window.