How to remove maximize button in Mac OS X toolbox in Qt

I have a window with a floating tool. It works fine on Windows, but I can’t get rid of the maximize button on Mac OS X. I tried to disable Qt::WindowMaximizeButtonHintand set the window to a fixed size. Nothing seems to work.

MyWidget::MyWidget( QWidget* parent )
:QWidget( parent, Qt::Tool | Qt::CustomizeWindowHint )
{
   setupUi( this );

   setFixedSize( sizeHint() ); // doesn't remove maximise button
   setWindowFlags( windowFlags() & ~Qt::WindowMaximizeButtonHint ); // doesn't remove maximise button
}

I do not want to use a frameless window. Any ideas? I am using Qt 4.4.

+5
source share
5 answers

This code from Richard Gustavsen from Nokia works in Qt 4.4:

class MyWidget : public QWidget
{
    public:

    MyWidget::MyWidget( QWidget* parent ) : QWidget(parent, Qt::Tool)
    {
    }

    void setVisible(bool visible)
    {
        QWidget::setVisible(visible);
        ChangeWindowAttributes(qt_mac_window_for(this), kWindowNoAttributes, kWindowFullZoomAttribute);
    }
};

Thanks to Richard and Nokia!

+4
source

Run the Qt windowflags sample application. Select the switch Tool, and then check:

  • Window title
  • Customize window
  • Window close button

, Mac OS X , , . . Mac OS X Window Manager.

, :

  • : setWindowFlags(Qt::Tool)
  • , , : setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint)
  • , , : setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::CustomizeWindowHint)
  • setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint)
  • : setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint)
+10

Qt::Dialog ( ):

, - , (.. , , ). QDialog. , QWidget:: windowModality. , - . , .

, , Qt::Dialog, Qt::Tool, , , .

+3

Here is a cross-platform way to do this. You have redefined your setVisible method of your QMainWindow or QWidget. In the same way, you can change any window flag that visually affects the window.

The reason this needs to be done is because the class must have window specifications before it actually displays the window.

void setVisible(bool visible)
{
    setWindowFlags( windowFlags() & ~Qt::WindowMaximizeButtonHint );
    QWidget::setVisible(visible);
}
+2
source

I was able to do this with

setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint)
+1
source

All Articles