Results 1 to 5 of 5

Thread: problem of customize the shape of QDialog

  1. #1
    Join Date
    Dec 2010
    Location
    Beijing.China
    Posts
    3
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default problem of customize the shape of QDialog

    customDlg.PNGcustomDlg.PNG

    hello everyone,

    i want to customize the shape of the QDialog and found a example for test, the code is:
    Qt Code:
    1. void customDlg::paintEvent(QPaintEvent* event)
    2. {
    3. Q_UNUSED(event)
    4.  
    5. QPainter painter(this);
    6. QStyle* style = this->style();
    7. QRect active_area = this->rect();
    8.  
    9. qDebug() << active_area;
    10.  
    11. int titlebar_height = 0;
    12.  
    13. // Titlebar.
    14. t_opt.initFrom(this);
    15.  
    16. titlebar_height = style->pixelMetric(QStyle::PM_TitleBarHeight, &t_opt, this);
    17.  
    18. qDebug() << titlebar_height;
    19.  
    20. t_opt.rect = QRect(0, 0, this->width(), titlebar_height);
    21. t_opt.titleBarState = this->windowState();
    22. t_opt.titleBarFlags = Qt::FramelessWindowHint;
    23. t_opt.text = t_opt.fontMetrics.elidedText(this->windowTitle(), Qt::ElideRight, t_opt.rect.width());
    24. style->drawComplexControl(QStyle::CC_TitleBar, &t_opt, &painter, this);
    25. style->drawItemText(&painter, t_opt.rect, Qt::AlignCenter, t_opt.palette, true, t_opt.text, QPalette::ToolTipText);
    26.  
    27. // Background widget.
    28. active_area.setTopLeft(QPoint(0, titlebar_height));
    29. this->setContentsMargins(0, titlebar_height, 0, 0);
    30.  
    31. QStyleOption w_opt;
    32. w_opt.initFrom(this);
    33. w_opt.rect = active_area;
    34.  
    35. qDebug() << w_opt.rect;
    36.  
    37. style->drawPrimitive(QStyle::PE_Widget, &w_opt, &painter, this);
    38. }
    To copy to clipboard, switch view to plain text mode 
    but there is a gray rect behind the round corner of the titlebar(see attachment), how can i remove(or hide) it?
    thanks!
    Last edited by high_flyer; 28th December 2010 at 08:59. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem of customize the shape of QDialog

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    julianfox0119 (29th December 2010)

  4. #3
    Join Date
    Dec 2010
    Location
    Beijing.China
    Posts
    3
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem of customize the shape of QDialog

    thanks a lot, that helps. but why there is a rect behind the titlebar? i don't really know what is it...
    i use "setAttribute(Qt::WA_TranslucentBackground, true);" but failed.

  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: problem of customize the shape of QDialog

    Because QDialog is a top level widget - which means it has not parent widget in which it is embedded, so it has no information about what is behind it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #5
    Join Date
    Dec 2010
    Location
    Beijing.China
    Posts
    3
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem of customize the shape of QDialog

    aha, thanks for the reply.

Similar Threads

  1. QDialog problem
    By bostero22 in forum Newbie
    Replies: 6
    Last Post: 27th December 2015, 18:26
  2. Customize QDialog's background using a SVG image
    By danielperaza in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 21:39
  3. Problem with QDialog
    By sudheer168 in forum Qt Programming
    Replies: 2
    Last Post: 2nd December 2009, 12:26
  4. The problem of customize QtEmbedded-4.5.0 for arm920t board!
    By jeazh in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 23rd May 2009, 19:35
  5. QDialog - customize the buttons
    By ape in forum Newbie
    Replies: 5
    Last Post: 12th March 2008, 08:59

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
  •  
Qt is a trademark of The Qt Company.