Results 1 to 12 of 12

Thread: Can't get title bar to disappear from widget

  1. #1
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Can't get title bar to disappear from widget

    Hello,

    I'm trying to make a full-screen, frameless QWidget (it's the QMainWindow). I have

    setWindowFlags( Qt::Window || Qt::FramelessWindowHint );

    which gets rid of everything except a bare title bar. I'd like to get rid of that too. If I try to just make the window larger than the screen--which is a bad solution anyway--then a status bar shows up on the bottom(?!). I'm using Qt 4.6 on a Mac. Anybody know what I should be doing? Thanks--

    Matt

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't get title bar to disappear from widget

    Reading the Qt::WindowFlags documentation, it looks like you might want Qt::Widget instead of Qt::Window. However, it also says that the Qt::Window bit cannot be cleared if the widget has no parent. So, you might try making the widget a child of the QDesktopWidget, which implies you might be able to clear the Qt::Window bit.

    And it probably was a typo in your posting, but you also want "|" and not "||" in the setWindowFlags() call.

    I would like to know if you try this and whether or not it works.

    -- edit --

    Looking further, it appears that if you set the flags Qt::Window | Qt::FramelessWindowHint | Qt::CustomizeWindowHint (and forget about the QDesktopWindow stuff above), this might do what you want.

    -- further edit --

    Verified using the QMainWindow-derived class in my own app that the above combination of flags removes the title bar.

    Qt Code:
    1. MyMainWindow mainWindow( 0, Qt::Window | Qt::FramelessWindowHint | Qt::CustomizeWindowHint );
    2. mainWindow.show();
    To copy to clipboard, switch view to plain text mode 

    However, you also can't move, minimize, maximize, close, or do anything else with the window except to resize it using the grab handle at the lower right. That is really, really unfriendly behavior. Is that how you want your users to view your app?
    Last edited by d_stranz; 24th October 2010 at 18:39.

  3. #3
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't get title bar to disappear from widget

    Hi d_stranz,

    Thanks very much, I will try this and let you know as soon as I do. You're right about the typo.

    Matt

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't get title bar to disappear from widget

    How about just calling QWidget::showFullScreen()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't get title bar to disappear from widget

    Quote Originally Posted by wysota View Post
    How about just calling QWidget::showFullScreen()?
    What if you don't want a full-screen widget? (Although the original poster said that's what he wanted).

    Wouldn't the flags method I suggested be a more general solution that would work regardless of window size?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't get title bar to disappear from widget

    Quote Originally Posted by d_stranz View Post
    What if you don't want a full-screen widget?
    Then you don't call QWidget::showFullScreen().

    Wouldn't the flags method I suggested be a more general solution that would work regardless of window size?
    There are many different "what ifs" we could discuss. If you have a frameless window, you can't even move it or close it so what's the point of having it this way?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't get title bar to disappear from widget

    Quote Originally Posted by wysota View Post
    Then you don't call QWidget::showFullScreen().
    Well, duh, I guess not

    Quote Originally Posted by wysota View Post
    There are many different "what ifs" we could discuss. If you have a frameless window, you can't even move it or close it so what's the point of having it this way?
    Granted, it's not appropriate behavior, but that doesn't answer the question. If for some insane reason I wanted to put a non-full screen, frameless window with no title bar in the user's face, how would I do it? Is the method I presented above the right way, or is there a better way?

    (Not trying to hijack the thread, just trying to learn something relevant to the original topic).

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't get title bar to disappear from widget

    Quote Originally Posted by d_stranz View Post
    If for some insane reason I wanted to put a non-full screen, frameless window with no title bar in the user's face, how would I do it? Is the method I presented above the right way, or is there a better way?
    I have no idea, feel free to experiment.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    d_stranz (25th October 2010)

  10. #9
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't get title bar to disappear from widget

    Hi,

    Thanks lykurg and wysota--but in fact neither solution worked! My code is simply this:

    Qt Code:
    1. MyMainWindow::MyMainWindow()
    2. {
    3. ui->setupUi(this); //It occurs to me now to try doing the flag settings before this, will try tomorrow
    4. ...
    5. Qt::WindowFlags flags( Qt::Window | Qt::FramelessWindowHint | Qt::CustumizeWindowHint);
    6. #ifdef Q_WS_X11
    7. flags |= Qt::X11BypassWindowManagerHint;
    8. #endif
    9. setWindowFlags(flags);
    10. setGeometry(scr_x,scr_y,scr_width,scr_height);
    11. showFullScreen();
    12. update();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Having the update() in or not doesn't make any difference as far as the bar is concerned.

    As for why I want a window like this, it's for a simple calibration program for calibrating an eye tracker. The subject doesn't interact with the window at all, just looks at the points that appear on the screen. I could get a window like I want using the QGL classes, but I wanted something simple and lightweight (and I wanted to get some practice with the QPainter class).

    Best,
    Matt

  11. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't get title bar to disappear from widget

    The major difference between my test (using my own QMainWindow-derived class) and yours is that I pass the flags into the MainWindow constructor:

    Qt Code:
    1. Qt::WindowFlags flags( Qt::Window | Qt::FramelessWindowHint | Qt::CustomizeWindowHint );
    2. MyMainWindow myMain( 0, flags );
    3. myMain.show();
    To copy to clipboard, switch view to plain text mode 

    whereas you are setting the flags after your MainWindow is partly constructed. I notice you also aren't calling the constructor for QMainWindow in the initialization of your MainWindow constructor; I always do this:

    Qt Code:
    1. MyMainWindow::MyMainWindow( QWidget * parent, Qt::WindowFlags flags )
    2. : QMainWindow( parent, flags )
    3. {
    4. // whatever
    5. }
    To copy to clipboard, switch view to plain text mode 

    but perhaps you just omitted this bit from your example.

    In my test, I also didn't display the main window as full screen, but I doubt this is crucial. The goal was to be able to remove the title bar, which my code does.

    -- few minutes later --

    I just inserted this at the end of my main window constructor:

    Qt Code:
    1. MyMainWindow::MyMainWindow( QWidget * parent, Qt::WindowFlags flags )
    2. : QMainWindow( parent, flags )
    3. {
    4. // whatever
    5.  
    6. showFullScreen();
    7. }
    To copy to clipboard, switch view to plain text mode 

    and I get a full-screen main window with no title bar.

    So, it is possible that the window flags need to be set as arguments to the constructor, not as a method call from within it.

    -- few more minutes later --

    Sorry, I was wrong - it doesn't matter whether the flags are passed as a constructor argument or set via a method call in the constructor. Either way works.

    Maybe you're just calling too many geometry-related methods. In my test, a simple sequence of

    Qt Code:
    1. setWindowFlags( Qt::Window | Qt::FramelessWindowHint | Qt::CustomizeWindowHint );
    2. showFullScreen();
    To copy to clipboard, switch view to plain text mode 
    in the constructor works just fine, as does calling
    Qt Code:
    1. myMain.showFullScreen();
    To copy to clipboard, switch view to plain text mode 
    from
    Qt Code:
    1. main()
    To copy to clipboard, switch view to plain text mode 
    .
    Last edited by d_stranz; 26th October 2010 at 03:26.

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't get title bar to disappear from widget

    What's the point of passing all those flags and setting geometry of the window manually if you are then calling showFullScreen()?

    Calling showFullScreen() and update() from a constructor is not a wise thing to do too. Your constructor should only contain the setupUi() call and then somewhere else in your code you should call showFullScreen().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #12
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't get title bar to disappear from widget

    Wow, this is frustrating, I responded to these comments several days ago but they didn't post, apparently. d_stranz--I actually did initialize QMainWindow in the MainWindow constructor, I just forgot to put that in the snippet. (My firewall at work blocks QtCentre ?!?! so I have to reply from home.) Passing window flags from the constructor didn't help. wysota--I had everything together in that snippet just to show that I had tried all those different things, I tried out showFullScreen(), manual settings independently as well.

    I'll try to keep update() and showFullScreen() out of the constructor, and see if that helps. Thank you both, so far--

    Matt

Similar Threads

  1. QWidget - Q_OBJECT makes the widget disappear
    By Sir Rogers in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2010, 23:39
  2. widget without title bar???
    By db in forum Newbie
    Replies: 3
    Last Post: 30th August 2007, 21:16
  3. QLabel::setText causes part of widget to disappear
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2007, 09:22
  4. Mouse dragged widget without title
    By Tonal in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2006, 12:28
  5. Replies: 9
    Last Post: 8th May 2006, 14:21

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.