i have attached image of tiltlebar. how can i implement that in Qmainwindow ...?
titlebar.jpg
i have attached image of tiltlebar. how can i implement that in Qmainwindow ...?
titlebar.jpg
1 Hide the borders
See Qt::FramelessWindowHint and the other window flags
2 Have a customized title bar with contents(like the title bar of itunes 11 where the player control buttons are packed inside the title bar).
You need to draw one yourself. For instance you could make a custom widget and place it on the top or similar.
3 Retain the drag around default property of the title bar.
And you need to implement this yourself as well. This is actually quite easy -- just make your custom widget react to mouse events. Rough plan:
in the mousePressEvent handler accept the event remember the position of the mouse press
you will then get mouse move events (as you accepted the press), so override mouseMoveEvent and move the window (move, setPos) by the 2D vector (... QPoint) currentPos - savedPos
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
pradeepreddyg95 (18th August 2013)
thnks karan i understood the concept but if i used Qt::FramelessWindowHint i cant move the widget ... if possible can you post few lines of code for better understanding ..
try this sample code
Qt Code:
... ... { if (event->buttons() & Qt::LeftButton) { move(event->globalPos() - m_dragPosition); event->accept(); } } { if (event->button() == Qt::LeftButton) { m_dragPosition = event->globalPos() - frameGeometry().topLeft(); event->accept(); } } ... ...To copy to clipboard, switch view to plain text mode
Hope this will help you..
CHEERS
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
pradeepreddyg95 (19th August 2013)
karankumar1609, thanks for such a detailed response.
I came across this thread wondering if there was any way to do it while still keeping the underlying platform's window decoration style. Any idea if that's possible?
And just dumping this related Qt feature/idea here for lack of a better place: We could add QWidget::addTitleBarWidget(QWidget* w, Position p = RightOfWindowTitle, Alignment a = Right) and then when m_TitleBarWidgets size goes from 0 to 1 then we setup the Qt::FramelessWindowHint, window moving, and listening to windowTitleChanged like karankumar1609 described; then, when m_TitleBarWidgets size goes back to 0 then undo those changes. But without being able to keep the underlying platform's window decoration style, this change/feature might be rejected![]()
And how to make it so that when you move the window, it decreases? And how do I make it so that only the one button gets caught when I hold the left mouse button from above, and not around the widget?
Bookmarks