I currently have a form that inherits from QDialog.
Now in order to hide the ? icon on the form I am doing something like this in the constructor.
foo::foo(QWidget *parent): QDialog(parent)
{
.....
this->setWindowFlags(Qt::WindowTitleHint);
}
The problem with this is that the Dialog does not show up. If I ommit the flags line it shows up. I am using QT 5.1.1
To answer the question, here the solution:
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
If you want the minimize and maximize options, do the following:
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint) | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
Eventually you want to call
this->setWindowFlags(this->windowFlags() | Qt::WindowTitleHint);
To get this to work on linux I had to use both options described above:
setFixedSize(width(), height());
setWindowFlags(Qt::Drawer);
The result is a dialog with only a close button.
Related
I've been searching around but haven't found an answer that helps me.
As the Title says i want to toggle the attribute "Qt::WA_TranslucentBackground" on/off.
I need WA_TranslucentBackground but some users of my app reported that this doesn't work in OBS(Open Broadcaster Software) so i have to make a seperate version without the TranslucentBackground.
My Code:
void MainWindow::action_widgetMode(){
if(displayOBS ==0){
this->setAttribute(Qt::WA_TranslucentBackground,true);
}else{
this->setAttribute(Qt::WA_TranslucentBackground,false);
}
this->setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
this->activateWindow();
this->setFocus();
this->show();
}
I am calling this function once upon start. And additionally on a checkbox click where i want to toggle it on/off. This code does work when i restart my application, but i want it to be immediate after the checkbox is checked/unchecked.
I have a Windows application that is built on QWizard (which inherits from QDialog). It must have a working maximization button.
By default maximization button is not even visible. i have set it to show, using:
auto flags = windowFlags();
flags ^= Qt::WindowContextHelpButtonHint;
flags |= Qt::WindowMinMaxButtonsHint;
setWindowFlags(flags);
However, it shows up disabled (grayed out, non-responding).
How can i enable it?
This works for me:
setWindowFlags(windowFlags() | Qt::CustomizeWindowHint |
Qt::WindowMinimizeButtonHint |
Qt::WindowMaximizeButtonHint |
Qt::WindowCloseButtonHint);
According to the documentation, you have to use the Qt::CustomizeWindowHint to be able to change the individual hints on the min/max buttons.
Someone here says this solved his problem:
setWindowFlags(Qt::Window);
I believe that you'll get better results creating your own dialog, but if you really wanna do it, one way is use window styles (Windows only, not cross-plataform).
Wizard class example:
class wizard : public QWizard
{
public:
wizard() {}
~wizard() {}
protected:
bool event(QEvent *event)
{
#ifdef Q_OS_WIN /*Make this code Windows OS only*/
if (event->type() == QEvent::WinIdChange)
{
HWND hwnd = (HWND)winId();
LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
lStyle |= (WS_MINIMIZEBOX | WS_MAXIMIZEBOX); /*Enable minimize and maximize*/
SetWindowLong(hwnd, GWL_STYLE, lStyle);
}
#endif
return QWizard::event(event);
}
};
I have this:
QWizard *wizard = new QWizard(this, Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint | Qt::Window);
wizard->setSizeGripEnabled(true);
Running Windows 10 on my dev-box, Qt 5.5.1, working for me.
One of my pages is a big QTableWidget that ends up being like an Excel sheet of some sorts (a big page to verify and edit-in-place a lot of data). Making the window resizable and let the user maximize it if they want makes it much easier to work with, instead of having to constantly scroll in a small dialog.
Normally you would say: If you need such a big window, it probably shouldn't be in a QWizard. But in this case it's really the middle of a workflow thing. A big 'verify, edit-if-needed and continue' page so it would be weird to stop the QWizard before and then having to start another one after or something.
I would like to know if it's possible to set my QMainWindow always on top .
I tried:
mainWindow.setWindowFlags(Qt::WindowStaysOnBottomHint);
mainWindow is a QMainWindow extended object.
But it doesn't work and my window disapear.
Yes, it is possible but there are two errors in your code:
You are clearing all flags but Qt::WindowStaysOnBottomHint which is set.
You're using Qt::WindowStaysOnBottomHint flag (which represent the opposite of what you want) instead of Qt::WindowStaysOnTopHint.
A correct way of doing that is:
Qt::WindowFlags flags = mainWindow.windowFlags();
mainWindow.setWindowFlags(flags | Qt::WindowStaysOnTopHint);
Note that on some window managers on X11 you also have to pass
Qt::X11BypassWindowManagerHint for this flag to work correctly.
In that case you should do:
Qt::WindowFlags flags = mainWindow.windowFlags();
mainWindow.setWindowFlags(flags | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
If you want to make a window as Dialog, there is another way. Just call setModal(true) or setWindowModality(), afterward show(). Unlike exec(), show() returns control to the caller instantaneously.It wont stuck as QDialog in exec().
i.e
setModel(true);//In Constructor
then while calling or invoking the new window,
MyWindow* myWindow = new MyWindow(this);
myWindow->show();
If I have a class which inherits QMainWindow, and I want it to only have the buttons; close, minimize and help in the window bar, how should I proceed?
If I use this code for the window flags:
setWindowFlags(Qt::Window | Qt::WindowContextHelpButtonHint | Qt::WindowMinimizeButtonHint);
It results in a window with maximize, minimize and close button.
If I exclude "WindowMinimizeButtonHint", there is only a help and close button.
How can I, if possible, make so there is a close, help AND minimize button ONLY?
According to Microsoft's documentation..
WS_EX_CONTEXTHELP cannot be used with the WS_MAXIMIZEBOX or
WS_MINIMIZEBOX styles.
which are the underlying windows system flags for Qt::WindowContextHelpButtonHint, Qt::WindowMinimizeButtonHint and Qt::WindowMaximizeButtonHint.
I don't think you can do this directly in Qt. I played around with the "Window Flags" example that ships with Qt and cannot get any combination that works.
If you really need this, you will probably have to use the Windows API directly. Here is a function I have used to enable/disable the close button in a Window. You could probably adapt it for your purposes. (Or, keep it simple and just add an extra "help" button somewhere on your form! :-))
#include "Windows.h"
#include "WinUser.h"
typedef HMENU (WINAPI*pGetSystemMenu)(HWND, BOOL);
typedef BOOL (WINAPI*pEnableMenuItem)(HMENU, UINT, UINT);
void myapp::SetCloseButtonEnabled(QWidget *target, bool enabled) {
// See msdn.microsoft.com/en-us/library/windows/desktop/ms647636(v=vs.85).aspx
QLibrary user32(QLatin1String("user32"));
pGetSystemMenu GetSystemMenu =
(pGetSystemMenu)user32.resolve("GetSystemMenu");
pEnableMenuItem EnableMenuItem =
(pEnableMenuItem)user32.resolve("EnableMenuItem");
HMENU menu = GetSystemMenu(target->winId(), false);
EnableMenuItem(menu,
SC_CLOSE,
MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED));
}
I'm trying to add a minimize button to my QDialog using this code in the constructor:
Qt::WindowFlags flags = windowFlags();
flags |= Qt::WindowMinMaxButtonsHint;
setWindowFlags(flags);
It's working on Windows but not on Linux.
Its a late answer but could be useful to others, I had the same problem and fixed like so:
Qt::WindowFlags flags = Qt::Window | Qt::WindowSystemMenuHint
| Qt::WindowMinimizeButtonHint
| Qt::WindowCloseButtonHint;
this->setWindowFlags(flags);
inside the overridden dialog constructor.