PDA

View Full Version : Can't get title bar to disappear from widget



MattPhillips
24th October 2010, 17:43
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

d_stranz
24th October 2010, 18:25
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.


MyMainWindow mainWindow( 0, Qt::Window | Qt::FramelessWindowHint | Qt::CustomizeWindowHint );
mainWindow.show();

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?

MattPhillips
24th October 2010, 18:48
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

wysota
24th October 2010, 21:50
How about just calling QWidget::showFullScreen()?

d_stranz
25th October 2010, 21:31
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?

wysota
25th October 2010, 21:44
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?

d_stranz
25th October 2010, 22:32
Then you don't call QWidget::showFullScreen().

Well, duh, I guess not :)


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).

wysota
25th October 2010, 22:46
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.

MattPhillips
26th October 2010, 02:48
Hi,

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


MyMainWindow::MyMainWindow()
{
ui->setupUi(this); //It occurs to me now to try doing the flag settings before this, will try tomorrow
...
Qt::WindowFlags flags( Qt::Window | Qt::FramelessWindowHint | Qt::CustumizeWindowHint);
#ifdef Q_WS_X11
flags |= Qt::X11BypassWindowManagerHint;
#endif
setWindowFlags(flags);
setGeometry(scr_x,scr_y,scr_width,scr_height);
showFullScreen();
update();
}

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

d_stranz
26th October 2010, 03:08
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::WindowFlags flags( Qt::Window | Qt::FramelessWindowHint | Qt::CustomizeWindowHint );
MyMainWindow myMain( 0, flags );
myMain.show();

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:


MyMainWindow::MyMainWindow( QWidget * parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
{
// whatever
}

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:


MyMainWindow::MyMainWindow( QWidget * parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
{
// whatever

showFullScreen();
}

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



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

in the constructor works just fine, as does calling
myMain.showFullScreen(); from
main().

wysota
26th October 2010, 08:59
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().

MattPhillips
2nd November 2010, 14:41
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