Assimilater
Assimilater

Reputation: 964

QDialog - Change default flags to exclude ? button

By default, QDialog applies a flag (I'm not exactly sure which) that makes a question mark button appear in the top-right. I have a class Login which inherits from QDialog that I was able to get rid of this question mark button by explicitly passing a more minimal set of flags like such

Login::Login(QWidget *parent) : QDialog(parent, Qt::WindowCloseButtonHint), ui(new Ui::Login) {}

However, I also use other dialogs in my program, such as QMessageBox and QInputDialog.

So my question: What are all of the default flags QDialog uses, and is there a way I can set the default so I don't have to pass flags on my own (vulnerable to perhaps omit some that are important for cross-platform ability) every time I initialize a new QDialog?

Upvotes: 1

Views: 765

Answers (1)

deW1
deW1

Reputation: 5660

You can just do:

Login::Login(QWidget *parent) : QDialog(parent, QDialog( ).windowFlags() & ~Qt::WindowContextHelpButtonHint ), ui(new Ui::Login) {}

~ is the bit negation operator.

windowFlags() contains the default flags of QDialog.

The same works for different flags as well so you don't modify flags you don't want to.

You asked about the default flags:

QFlags(0x1|0x2|0x1000|0x2000|0x10000|0x8000000)

To create a default you could make a global variable containing the WindowFlags you prefer.

For example:

QFlags< Qt::WindowFlags > defaultFlags;

defaultFlags = QDialog( ).windowFlags( );

defaultFlags = defaultFlags & ~Qt::WindowContextHelpButtonHint;

Now whenever you create a Dialog for example you can pass the defaultFlags as second argument.


Alternatively you could just write a wrapper around the QDialog Class which you can then fully modify to your liking and use it without having the need to add extra parameters or to repeat yourself:

class CustomDialog : public QDialog
{
    Q_OBJECT

public:
    explicit CustomDialog( QWidget *parent = 0);

};

Upvotes: 3

Related Questions