PDA

View Full Version : Disabling the Maximize button in QMainWindow ?



sunil.thaha
8th September 2006, 13:28
Hi Guys

How do we diable the Maximize Button in QMainWindow,

I am using KDE, and the I tried Playing the WindowFlags example. But to No avail.

I also tried doing this


#include <QApplication>
#include <QMainWindow>

int main(int argc, char *argv[]) {

QApplication app( argc, argv );

QMainWindow win(0, Qt::WindowTitleHint |
Qt::WindowSystemMenuHint |
Qt::WindowMinimizeButtonHint );

win.show();

return app.exec();
}



But failed,

Any Idea

sir_johann
8th September 2006, 23:50
I had tried with diferents Qt Wflags, but it seems no work. So the only way I had found is this:

// I use this directive in this way:
#include <qapplication.h>
#include <qmainwindow.h>

int main(int argc, char *argv[]) {

QApplication app( argc, argv );
QMainWindow *win;
win = new QMainWindow();

win->setFixedSize(200, 200);
app.setMainWidget(win);
win->show();
return app.exec();

}

If you set the window size, the maximize button won't be shown.
I hope this be useful. Regards.

Djony
9th January 2007, 11:22
I have tried this, but I am using Qt 4.1.4, and my compiler gives me error:


class QApplication' has no member named 'setMainWidget'

Is there any other way to disable maximize button?

momesana
9th January 2007, 12:47
I have tried this, but I am using Qt 4.1.4, and my compiler gives me error:
class QApplication' has no member named 'setMainWidget'


from http://doc.trolltech.com/4.2/porting4.html#qapplication


QApplication::setMainWidget (http://doc.trolltech.com/4.2/qapplication-qt3.html#setMainWidget)() is no longer used. When all an application's windows are closed, the application will exit normally.


The guy, posting the above code probably is using Qt-3.* whereas you are using Qt-4.*.

Djony
9th January 2007, 12:50
I got that, but the question with maximize button still stands.

ucomesdag
10th January 2007, 05:14
This should do it...;)


#include <QtGui/QApplication>
#include <QMainWindow>

int main(int argc, char *argv[]) {

QApplication app( argc, argv );

QMainWindow win;
win.setWindowFlags( Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowSystemMenuHint);

win.show();

return app.exec();
};

sunil.thaha
10th January 2007, 07:02
Works well in Windows Xp , but as I mentioned first, It does not work in KDE. KDE seems to ignore the Flags :confused:

ucomesdag
10th January 2007, 07:07
Works well in Windows Xp , but as I mentioned first, It does not work in KDE. KDE seems to ignore the Flags :confused:

It got it running fine in KDE maximize button is gone as in windows it's only disabled.

sunil.thaha
10th January 2007, 07:38
I am using KDE 3.3.1 with Plastique Theme, See the screen shot. The maximize button is still there

Djony
10th January 2007, 11:10
Thank you, ucomesdag! Is there way to make it disappear completely?

vishal.chauhan
10th January 2007, 11:21
You can set same maximum and minimum size As.

MainForm *MainFormObj=new MainForm(0);
MainFormObj->show();

MainFormObj->setMaximumSize (849,626);
MainFormObj->setMinimumSize (849,626);

I think it will work.I m using this on my mac using qt 4.2.2.

Djony
10th January 2007, 11:29
Tried it. It doesn't work on WinXP.

vishal.chauhan
10th January 2007, 12:47
what is Happening when you r doing this.
Is there is an error?
Actually I am running it correctly and donot know why it is not working in XP.

check one thing that U also set the geometry of main window as

MainForm *MainFormObj=new MainForm(0);
MainFormObj->show();

MainFormObj->setMaximumSize (849,626);
MainFormObj->setMinimumSize (849,626);

MainFormObj->setGeometry(5,42,849,626); //add this line

Try this.

ucomesdag
10th January 2007, 18:44
I am using KDE 3.3.1 with Plastique Theme, See the screen shot. The maximize button is still there

Might be the version of KDE I got 3.5.5 running and it works.


Thank you, ucomesdag! Is there way to make it disappear completely?

On windows XP it just disables the button but it doesn't disappear.

netmat
16th April 2010, 11:45
Hi Sunil.thaha,

How did you solve the above problem? Could you manage to make the maximize button disappeared?

Regards,
~NM

faldzip
16th April 2010, 11:58
Read about Qt::WindowFlags

netmat
16th April 2010, 12:15
hi,

Those flags are not working properly. those working fine on windows but not on Mac. Even I am not being able to have close button on mac.
I hv posted my code here. http://www.qtcentre.org/threads/29900-close-button-not-there-in-Mac-but-its-in-window?p=140063#post140063


thanks anyway.

sherifomran
26th June 2017, 13:31
check this example
http://doc.qt.io/qt-5/qtwidgets-widgets-windowflags-example.html

you should use
qt::window | qt::windowminimizebuttonhint | qt::closebuttonhint | qt::customizewindowhint


you can not remove the maximize button without the customizewindowhint