Results 1 to 6 of 6

Thread: how to draw custom titlebar for QMainWindow ... ?

  1. #1
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Thanks
    8
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Thumbs up how to draw custom titlebar for QMainWindow ... ?

    i have attached image of tiltlebar. how can i implement that in Qmainwindow ...?



    titlebar.jpg

  2. #2
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to draw custom titlebar for QMainWindow ... ?

    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.

  3. The following user says thank you to karankumar1609 for this useful post:

    pradeepreddyg95 (18th August 2013)

  4. #3
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Thanks
    8
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to draw custom titlebar for QMainWindow ... ?

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

  5. #4
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to draw custom titlebar for QMainWindow ... ?

    try this sample code

    Qt Code:
    1. ...
    2. ...
    3. void MyWindow::mouseMoveEvent(QMouseEvent *event)
    4. {
    5. if (event->buttons() & Qt::LeftButton) {
    6. move(event->globalPos() - m_dragPosition);
    7. event->accept();
    8. }
    9. }
    10. void MyWindow::mousePressEvent(QMouseEvent *event)
    11. {
    12. if (event->button() == Qt::LeftButton) {
    13. m_dragPosition = event->globalPos() - frameGeometry().topLeft();
    14. event->accept();
    15. }
    16. }
    17. ...
    18. ...
    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.

  6. The following user says thank you to karankumar1609 for this useful post:

    pradeepreddyg95 (19th August 2013)

  7. #5

    Default Re: how to draw custom titlebar for QMainWindow ... ?

    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

  8. #6
    Join Date
    May 2017
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to draw custom titlebar for QMainWindow ... ?

    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?

Similar Threads

  1. Replies: 6
    Last Post: 16th April 2013, 16:13
  2. custom widget with the windows7 style titlebar??
    By pirlogy in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2011, 00:30
  3. how to disable double click event on qmainwindow titlebar?
    By banlinhtienphong in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2011, 10:23
  4. To draw a custom scale
    By Indalo in forum Qwt
    Replies: 1
    Last Post: 30th November 2009, 13:24
  5. QMainWindow with no titlebar in OSX
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2007, 12:15

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.