PDA

View Full Version : how to implement this MainWindow just like iTunes



yxmaomao
1st July 2008, 06:18
how to implement this MainWindow just like iTunes ?

I mean, no caption, just put menu bar in the main window, we can resize the main window from the four directions, please see the itunes.

Thanks in advance!

wysota
1st July 2008, 07:31
Would you care to provide more details? From what I see iTunes window has a title and is in all means a regular classical main window.

yxmaomao
1st July 2008, 08:48
As you know, default for main window there is icon + title at the left-most, min/max/close buttons at the right-most, border lines at four directions' boder which you can resize the window.

at the bottom of the windows title and icon there is MenuBar then Tool Bar

But when you run the iTunes, you can see these are different.
So could you tell me how to impelment the mainwindow like the iTunes.
I have try to setWindowFlags( Qt::FramelessWindowHint ), but in this case I can't get
the resize indicator at the four direction's border, at the same time all the relative system's hint menu will be lost.

aamer4yu
1st July 2008, 10:20
Isnt this I tunes like a custom shaped widget ??
With menus drawn with transparent background ?? and close/maximize/minimize buttons custom made ??

hope am not wrong :rolleyes:

wysota
1st July 2008, 11:02
Isnt this I tunes like a custom shaped widget ??
With menus drawn with transparent background ?? and close/maximize/minimize buttons custom made ??

This is my impression as well...

yxmaomao
2nd July 2008, 05:15
yes I can customise the titlebar, but there are still two problems,
1. how can I show system context menus for eg min/max/ restore/move etc. you know when applicaton at the system task bar, right-click system menu will popup, but when I use setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint); OS context menu is not right.

2. after setWindowFlags(Qt::FramelessWindowHint), my application don't repsone system (window+M ) keys which should make my application minimise.

aamer4yu
2nd July 2008, 05:32
1. how can I show system context menus for eg min/max/ restore/move etc. you know when applicaton at the system task bar, right-click system menu will popup, but when I use setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint); OS context menu is not right.

You can catch the QWidget::contextMenuEvent() I guess. The menu you are talking about is shown on right click of title bar, and also left mouse button click near the left most area of the title bar. I dont think it shud be difficult to mimick the same


2. after setWindowFlags(Qt::FramelessWindowHint), my application don't repsone system (window+M ) keys which should make my application minimise.
No idea right now. Didnt try it yet :D

yxmaomao
7th July 2008, 09:22
I have tried many ways, still can't implement this function, Anybody know?

yxmaomao
7th July 2008, 09:25
I am wondering how the iTunes implement this with Qt
1. iTunes can response system shortcut key : windows + M combined key to minimise
2. iTunes response system context menu very well

marf
8th July 2008, 17:06
I have also been wondering how to do something like this. I want to use MainWindow, but I want to be able to draw my own titlebar, min, max, close buttons, and menus etc. All using custom graphics I made in photoshop/gimp. Is there any good tutorials/explanation about how to accomplish this?

luf
8th July 2008, 17:39
I have also been wondering how to do something like this. I want to use MainWindow, but I want to be able to draw my own titlebar, min, max, close buttons, and menus etc. All using custom graphics I made in photoshop/gimp. Is there any good tutorials/explanation about how to accomplish this?

2 paths to choose:

Stylesheets, see Qt Style Sheets (http://doc.trolltech.com/4.4/stylesheet.html)
QStyle, see QStyle - creating custom styles (http://doc.trolltech.com/4.4/qstyle.html#creating-a-custom-style)


As for both it's a bit try-and-learn. There are some limitations on both.

What you can do to achieve a similar look to itunes is :
a) set your QMainWindow borderless, use a stylesheet on the QMenuBar. create a subclassed QMenu object and create a "title-like" stylesheet for that one. When creating the menubar, add your menuitems, then add a stretch, add your logo/title, add stretch, add padding after the stretch that is the same as the menuitems before... Lot of tuning hassle and work, but in theory it should work.

b) reimplement the drawing of a mainwindow entirely, and write it all by hand


c) QStyle as mentioned above.

for the windows+m issue, when using a borderless window, you might have to call: QWidget::activateWindow() on your mainwindow to get keyboard focus.

cheers,
Leif

wysota
8th July 2008, 18:57
Search the forum for "skins" or something similar. There has been a thread about a solution to completely modify the look of a window, including its title bar.

yxmaomao
9th July 2008, 00:24
2 paths to choose:

Stylesheets, see Qt Style Sheets (http://doc.trolltech.com/4.4/stylesheet.html)
QStyle, see QStyle - creating custom styles (http://doc.trolltech.com/4.4/qstyle.html#creating-a-custom-style)


As for both it's a bit try-and-learn. There are some limitations on both.

What you can do to achieve a similar look to itunes is :
a) set your QMainWindow borderless, use a stylesheet on the QMenuBar. create a subclassed QMenu object and create a "title-like" stylesheet for that one. When creating the menubar, add your menuitems, then add a stretch, add your logo/title, add stretch, add padding after the stretch that is the same as the menuitems before... Lot of tuning hassle and work, but in theory it should work.

b) reimplement the drawing of a mainwindow entirely, and write it all by hand


c) QStyle as mentioned above.

for the windows+m issue, when using a borderless window, you might have to call: QWidget::activateWindow() on your mainwindow to get keyboard focus.
---------------------------------------------------------------------------------------


cheers,
Leif

Unfortunately even if I call activateWindow(), windows+m still doesn't work.

yxmaomao
16th July 2008, 02:03
anyone has an idea for this now??

wysota
16th July 2008, 10:09
What problem are you currently facing and what did you already try to solve it?

yxmaomao
17th July 2008, 00:29
My problem is :
set my MainWindow as frameless, then use setMask make main windows like iTunes
but now my app can't response to Windows + M combined shortcut keys to minimize window, and system context menu can't be shown now.

Actually I just want to get a window face which likes iTunes' and can response to system context menu and combined Windows+M shortcut keys correctly.

wysota
17th July 2008, 07:14
As for Windows+M, you can emulate it using a shortcut and QWidget API.

yxmaomao
17th July 2008, 23:57
but when should I emulate this thing, I don't know when user click that keys you know

yxmaomao
22nd July 2008, 05:51
still nobody how to do this?

wysota
22nd July 2008, 22:57
Have you seen QShortCut docs?

yxmaomao
23rd July 2008, 07:26
hi wysota,
I think you missed my question, when your application is not active status, how can you emulate the shortcuts keys.
QShortCut sounds only work for activated widget.

wysota
25th July 2008, 15:25
Isn't it how it works? That The "M" shortcut minimizes the current window?

jpn
27th July 2008, 10:05
Isn't it how it works? That The "M" shortcut minimizes the current window?
Actually it minimizes all windows. But the problem is that Windows won't send necessary messages to a frameless window.

wysota
27th July 2008, 11:07
Well, that doesn't surprise me :) One can always hook to some other window using regular WinAPI means and intercept a message directed to another window. It's a dirty hack of course...

trytry
10th August 2008, 03:45
Do you mean that you want to make the caption unified to the tool bar? Please try to use setUnifiedTitleAndToolBarOnMac(true) in your main window. Hope this can help.

The Storm
11th August 2008, 11:15
setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint);
Before version 4.4.0 this code has worked as I espected, it created a frameless window but with titlebar menu and all the combinations like ctrl+m has been working good.
Now sinse Qt 4.4.0 when the flag Qt::WindowSystemMenuHint is put the system frame of the window is back and without it you will not have the title bar menu and the shortcuts. Nasty uh... :)

magnosis
28th April 2009, 22:33
I am trying something similar.

While I managed to apply some styles to the Menubar and Toolbar, I am still facing a wall regarding margins/padding on the Central area of QMainWindow

What happens is that whatever "something" I add as QMainWindow::setCentralWidget( something ), this main area *always* show a padding.

I want to add a customer banner just below the Menubar (no Toolbar in my case). But this banner can never expand all the way to the top (right below the menu) and to the sides, there is always that 5-10pix padding.

I've tried a lot of different things in stylesheets, even this doesn't fix it :

*,
QMainWindow,
QMainWindow * {
spacing: 0;
padding: 0;
margin: 0;
}

Any advice would be really really appreciated !

mchara
31st July 2009, 09:41
How about bool QCoreApplication::winEventFilter ( MSG * msg, long * result ) or virtual bool QWidget::winEvent ( MSG * message, long * result )?
Sorry, i hadn't time to check it, but perhaps SC_MINIMIZE message is still sent by windows to frameless windows, but qt doesn't interpret it for frameless windows. I'm not sure about it but i think it's workth a try.

As for context menu, you could try to emulate it with popup QMenu or if you want to call real one try sending WM_SYSCOMMAND message with wParam=SC_KEYMENU
(http://msdn.microsoft.com/en-us/library/ms646360(VS.85).aspx)