Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Qt::Popup with titlebar

  1. #1
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt::Popup with titlebar

    Hi,

    I have a subclass of QWidget. And I have set windowFlags to Qt::Popup in the constructor. But when popup widget is displayed, it comes without titlebar. I have also tried Qt::Popup | Qt::WindowTitleHint. But it's still displayed without titlebar.

    How can I get popup with title bar?

    Please reply.

    Thanks & Regards,
    Keyur Shah

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Popup with titlebar

    With Qt::Popup you wont get the title bar.
    Dont set any flags, and you will get the widget with a title bar. You can also use QDialog , or QWidget with Qt::Tool flag set,, whatever suits you.

  3. #3
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    Thanks for your reply.

    Oh... But none of other flags gives me what i wants.
    QDialog are providing only application specific functionaliy.

    I want my widget to close if user clicks outside the widget or better outside the application too.

    So how can I get such things without using Qt::Popup flag?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Popup with titlebar

    Well, if thats the case, I can think only of the following for now -
    Draw the title bar yourself in the paintevent of your widget. And you can have the Qt::Popup flag set on your widget too

  5. #5
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    Is there any method using which I can draw titlebar of widget by myself?

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Popup with titlebar

    QStylePainter::drawComplexControl(QStyle::CC_TitleBar,option);

  7. #7
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    Still it is diaplyed without titlebar.

    I have written following code in paintEvent

    QStylePainter painter( this );
    QStyleOptionTitleBar option;
    painter.drawComplexControl( QStyle::CC_TitleBar, option );

    Please let me know if I am missing something.

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Popup with titlebar

    try setting option.initFrom(this);
    But I doubt if QStyle will permit you draw a title bar on a Qt::Popup widget.

    You can try setting the QStyleOptionTitleBar::titleBarFlags and see if draws.

  9. #9
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    How to set QStyleOptionTitleBar::titleBarFlags???

    Do you mean set the widget->setWindowFlags(Qt::WindowTitleHint) ?

  10. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Popup with titlebar

    What is the exact functionality you want and get with Qt::Popup and you can't get with other flags?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  11. #11
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    With Qt::Popup, If I click anywhere including outside application, only the popup will be dismissed and no other window has any effect.

  12. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Popup with titlebar

    I got it working by -
    Qt Code:
    1. class PopupWithTitle : public QWidget
    2. {
    3. public:
    4. PopupWithTitle(QWidget* parent =0);
    5. ~PopupWithTitle();
    6. protected:
    7. void paintEvent ( QPaintEvent * event ) ;
    8.  
    9. };
    10.  
    11. PopupWithTitle::PopupWithTitle(QWidget* parent) : QWidget(parent)
    12. {
    13. setWindowFlags( Qt::Popup);
    14. setFixedSize(300,200);
    15. }
    16.  
    17. PopupWithTitle::~PopupWithTitle()
    18. {
    19.  
    20. }
    21.  
    22. void PopupWithTitle::paintEvent ( QPaintEvent * event )
    23. {
    24. QWidget::paintEvent(event);
    25.  
    26. QStylePainter stylePainter(this);
    27. option.initFrom(this);
    28. option.text = "Popup title";
    29. option.rect = rect();
    30. option.rect.setHeight(20);
    31. stylePainter.drawComplexControl(QStyle::CC_TitleBar,option);
    32. }
    To copy to clipboard, switch view to plain text mode 

    But yes, the window doesnt move, if you need that, you need to implement yourself

  13. #13
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    Thanks.. I have got popup with titlebar.

    I will try to implement dragging & coloring the titlebar with close button.

    And will let you know if will get any problems.

    If someone already know please reply.

  14. #14
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Popup with titlebar

    Hint :
    QStylePainter::drawItemPixmap
    QStyle::standardIcon and QStyle::SP_TitleBarCloseButton

    mousePressEvent

  15. The following user says thank you to aamer4yu for this useful post:

    keyur259 (25th January 2010)

  16. #15
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    Hi, I have got titlebar & close button. And also able to drag it now using coding.

    But I am unable to get text in titlebar. Shall we have to add control for it in paintEvent?

    And color of the titlebar is not the same as other windows have. How can I get the general window titlebar color & set it for cuurrent titlebar?

  17. #16
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt::Popup with titlebar

    Did you try the code I posted ? I could get text in the title bar.

    Anyways the functionalities you are adding, I guess it would be better to simply use a modal QDialog instead of so many turnarounds.

  18. #17
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    I have used the code that you have posted using which I have got the titlebar without text. Then also I wil re-check.

    The problem with modal dialog is It is only application specific modal.

  19. #18
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    How can I get the general window titlebar color & set it for cuurrent titlebar?

  20. #19
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Wink Re: Qt::Popup with titlebar

    Quote Originally Posted by keyur259 View Post
    Hi, I have got titlebar & close button. And also able to drag it now using coding.
    Wanna share your code how to add close button ? And maybe drag function if you finish it.

  21. #20
    Join Date
    Jan 2010
    Posts
    22
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt::Popup with titlebar

    For Close Button, Title Bar With Text & PopUp with Frame

    Qt Code:
    1. void CustomPopUp::paintEvent( QPaintEvent* event )
    2. {
    3. QWidget::paintEvent( event );
    4.  
    5. QStylePainter painter( this );
    6. QPalette tPalette = palette();
    7. tPalette.setColor( QPalette::WindowText, QColor( Qt::white ) );
    8.  
    9. QStyleOptionTitleBar titleOption;
    10. titleOption.initFrom( this );
    11. titleOption.text = "Custom PopUp";
    12. titleOption.rect = rect();
    13. titleOption.rect.setHeight( 23 );
    14. titleOption.titleBarState = (int)Qt::WindowActive | ~Qt::WindowMinimized;
    15. painter.drawComplexControl( QStyle::CC_TitleBar, titleOption );
    16.  
    17. QStyleOptionFrame frameOption;
    18. frameOption.initFrom( this );
    19. frameOption.rect = QRect( rect().x(), rect().y() + 23, rect().width(), rect().height() - 23 );
    20. painter.drawPrimitive( QStyle::PE_Frame, frameOption );
    21.  
    22. QIcon icon = style()->standardIcon( QStyle::SP_DialogCloseButton );
    23. QRect r = QRect( 0, 0, rect().width() - 5, 23 );
    24. painter.drawItemPixmap( r, (int)Qt::AlignRight | Qt::AlignVCenter, icon.pixmap( 19, 19 ) );
    25.  
    26. r = QRect( 0, 0, rect().width(), 23 );
    27. QFont f = painter.font();
    28. f.setBold( true );
    29. painter.setFont( f );
    30. painter.drawItemText( r, (int)Qt::AlignHCenter | Qt::AlignVCenter, tPalette, true, "Custom PopUp", QPalette::WindowText );
    31. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Mac titlebar buttons Issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 5
    Last Post: 9th July 2009, 21:45
  2. Replies: 3
    Last Post: 17th May 2009, 20:17
  3. TitleBar color
    By chethana in forum General Programming
    Replies: 1
    Last Post: 14th November 2008, 17:20
  4. Color of Titlebar and Menubar
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 16th August 2007, 10:12
  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.