tags:

views:

1031

answers:

5

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.

+1  A: 

You could try setting the window flag to include Qt::Dialog (bold added):

Indicates that the widget is a window that should be decorated as a dialog (i.e., typically no maximize or minimize buttons in the title bar). This is the default type for QDialog. If you want to use it as a modal dialog, it should be launched from another window, or have a parent and used with the QWidget::windowModality property. If you make it modal, the dialog will prevent other top-level windows in the application from getting any input. We refer to a top-level window that has a parent as a secondary window.

I don't know what would happen if you tried setting both Qt::Dialog and Qt::Tool, but it might be worth investigating.

Caleb Huitt - cjhuitt
Tried both Qt::Dialog | Qt::Tool and Qt::Dialog. Still had a maximise button in both cases!
Andy Brice
+2  A: 

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)
Kamil Klimek
Kamil,Great answer. Unfortunately it seems that Qt::WindowCloseButtonHint is not available in Qt 4.4!
Andy Brice
Sorry for that but I'm currently using Qt 4.6, but my intention was to make you run windowflags example from Qt, so you could easily and quite fast try most options
Kamil Klimek
I've tried the windowflags example in Qt 4.4, but couldn't find a combination that removed the maximize button.
Andy Brice
why won't you upgrade Qt?
Kamil Klimek
+2  A: 

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!

Andy Brice
A: 

I was able to do it with

setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint)

Regards, Esteban

Esteban
A: 

So there is no way to hide or remove maximize button(not just disabling) with out loosing the minimize buttton? (I want it on all platforms- mac, win, linux)

any pointer to any paltform specific stuff or work around?

Best Regards, Alex

Alex