Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove maximize button in Mac OS X tool window in Qt

Tags:

macos

qt

I have a floating tool window. It works fine on Windows, but I can't get rid of the maximise button on Mac OS X. I have tried unsetting Qt::WindowMaximizeButtonHint and setting the window to 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 don't want to use a frameless window. Any ideas? I am using Qt 4.4.

like image 325
Andy Brice Avatar asked Jan 13 '10 18:01

Andy Brice


2 Answers

Launch Qt windowflags example application. Choose Tool radio button and then check:

  • Window title
  • Customize window
  • Window close button

It's the only way I found on Mac OS X to achieve what you want BUT you will loose minimize button. There's no other way. That's Mac OS X Window Manager limitation.

Summarizing, there are only five sets of buttons in title bar:

  1. All buttons visible and all buttons enabled: setWindowFlags(Qt::Tool)
  2. All buttons visible, close and maximize buttons enabled, minimize button disabled: setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint)
  3. All buttons visible, maximize button enabled, close and minimize disabled: setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowMaximizeButtonHint | Qt::CustomizeWindowHint)
  4. Only close button is visible and enabled setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint)
  5. No buttons in title bar: setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint)
like image 57
Kamil Klimek Avatar answered Oct 12 '22 22:10

Kamil Klimek


This code from Richard Gustavsen of 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 Richard and Nokia!

like image 37
Andy Brice Avatar answered Oct 13 '22 00:10

Andy Brice