Results 1 to 9 of 9

Thread: How to hide Close Button "X" on Widget ?

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default How to hide Close Button "X" on Widget ?

    Hi all

    Working on Qt4.3.4 on Windows XP, I want to know how to hide Close (X) that is appearing on right hand side of the widget.


    Earlier i had working on MAC OS, there i set WindowModality to Qt::ApplicationModal , then close button hides,

    Is there any flag for windows to hide the close button.


    Regards

    Merry
    Always Believe in Urself
    Merry

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to hide Close Button "X" on Widget ?

    Try this
    setWindowFlags(Qt::WindowTitleHint);
    or
    setWindowFlags(Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint);

    Hope it helps

  3. #3
    Join Date
    Mar 2010
    Posts
    92
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to hide Close Button "X" on Widget ?

    Quote Originally Posted by aamer4yu View Post
    Try this
    setWindowFlags(Qt::WindowTitleHint);
    or
    setWindowFlags(Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint);

    Hope it helps



    i want disable close button,how do that do ?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to hide Close Button "X" on Widget ?

    Disable or hide ??

    Disable, I guess it will be difficult.

  5. #5
    Join Date
    Apr 2010
    Posts
    98
    Thanks
    19
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to hide Close Button "X" on Widget ?

    If you cannot find a way to disable or hide it.Perhaps this way would help:
    1.remove the window frame by using setWindowFlags()
    2.draw the window frame yourself.

    But you have a bunch of work to do,if you choose this way.
    It's not the goodbye that hurts,but the flashback that follow.

  6. #6
    Join Date
    Apr 2010
    Posts
    98
    Thanks
    19
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to hide Close Button "X" on Widget ?

    Ok,I find the flag.
    See the screenshot below:

    use Qt::CustomizeWindowHint,you will get no X button,but also no title....
    It's not the goodbye that hurts,but the flashback that follow.

  7. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to hide Close Button "X" on Widget ?

    Try http://www.qtcentre.org/threads/2454...112#post142112

    or alternatively, you could draw the title bar yourself.

  8. #8
    Join Date
    Jan 2010
    Posts
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to hide Close Button "X" on Widget ?

    I did it a few minutes ago for my application. In main.cpp, write:

    widget.setWindowFlags ( Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    widget.show();
    Now you do not have close button, neither a menu close and ALT-F4 won't work.
    Hope this can be helpful.

    I'm using Qt4 under Linux

  9. The following 3 users say thank you to arnaizf for this useful post:

    francomartins (20th June 2012), maratk1n (14th April 2017), ShaChris23 (29th July 2010)

  10. #9
    Join Date
    Jan 2020
    Posts
    3
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How to hide Close Button "X" on Widget ?

    Quote Originally Posted by arnaizf View Post
    I did it a few minutes ago for my application. In main.cpp, write:



    Now you do not have close button, neither a menu close and ALT-F4 won't work.
    Hope this can be helpful.

    I'm using Qt4 under Linux
    I believe another way around would be hijacking close event, add this ti header file:
    Qt Code:
    1. private:
    2. void closeEvent(QCloseEvent *event) override;
    To copy to clipboard, switch view to plain text mode 

    and this to cpp file:
    Qt Code:
    1. void MainWindow::closeEvent(QCloseEvent *event)
    2. {
    3. cout << "Here in close" << endl;
    4. event->ignore();
    5. }
    To copy to clipboard, switch view to plain text mode 

    More info? https://doc.qt.io/qt-5/qwidget.html#closeEvent

Similar Threads

  1. Close Button on Modal Widget?
    By vishal.chauhan in forum Qt Programming
    Replies: 5
    Last Post: 18th February 2008, 12:38
  2. Replies: 3
    Last Post: 17th October 2007, 13:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.