Results 1 to 5 of 5

Thread: problem of customize the shape of QDialog

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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.