Results 1 to 5 of 5

Thread: Round window

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Round window

    Hey there,

    I'm trying to display a window widget with rounded edges.
    I've tryed with setMask + specifying a mask, but the result is not convincing.



    Qt Code:
    1. QRect maskRect(rect().x() + 1, rect().y() + 1,
    2. rect().width() - 1, rect().height() - 1);
    3.  
    4. setMask(QRegion(ZePainterController::get()->DrawRoundRect(maskRect,
    5. 2000 / maskRect.width(), 2000 / maskRect.height()).toFillPolygon().toPolygon()));
    To copy to clipboard, switch view to plain text mode 

    Don't know If I should use a mask bitmap ?
    Last edited by bunjee; 23rd November 2007 at 14:33.

  2. #2
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Round window

    Anybody has a code snipet for this ?

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Round window

    QwtDial ( http://qwt.sourceforge.net/class_qwt_dial.html ) is such a widget. Look at the code of QwtDial::updateMask.

    HTH,
    Uwe

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Round window

    Quote Originally Posted by Uwe View Post
    QwtDial ( http://qwt.sourceforge.net/class_qwt_dial.html ) is such a widget. Look at the code of QwtDial::updateMask.

    HTH,
    Uwe
    Unfortunately that won't work for windows. There is no antialiasing done for top-level windows. For an alternative, see this http://www.qtcentre.org/forum/f-qt-s...sses-9301.html.

  5. #5
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Round window

    I've coded rounded painting path to use with my mask :

    Qt Code:
    1.  
    2. path.moveTo(r.x() + 7, r.y());
    3. path.lineTo(r.x() + r.width() - 7, r.y());
    4.  
    5. // Upper right
    6. path.lineTo(r.x() + r.width() - 6, r.y() + 1);
    7. path.lineTo(r.x() + r.width() - 5, r.y() + 1);
    8.  
    9. path.lineTo(r.x() + r.width() - 1, r.y() + 5);
    10. path.lineTo(r.x() + r.width() - 1, r.y() + 6);
    11. path.lineTo(r.x() + r.width(), r.y() + 7);
    12.  
    13. path.lineTo(r.x() + r.width(), r.y() + r.height() - 7);
    14.  
    15. // Lower right
    16. path.lineTo(r.x() + r.width() - 1, r.y() + r.height() - 6);
    17. path.lineTo(r.x() + r.width() - 1, r.y() + r.height() - 5);
    18.  
    19. path.lineTo(r.x() + r.width() - 5, r.y() + r.height() - 1);
    20. path.lineTo(r.x() + r.width() - 6, r.y() + r.height() - 1);
    21. path.lineTo(r.x() + r.width() - 7, r.y() + r.height());
    22.  
    23. path.lineTo(r.x() + 7, r.y() + r.height());
    24.  
    25. // Lower left
    26. path.lineTo(r.x() + 6, r.y() + r.height() - 1);
    27. path.lineTo(r.x() + 5, r.y() + r.height() - 1);
    28.  
    29. path.lineTo(r.x() + 1, r.y() + r.height() - 5);
    30. path.lineTo(r.x() + 1, r.y() + r.height() - 6);
    31. path.lineTo(r.x(), r.y() + r.height() - 7);
    32.  
    33. path.lineTo(r.x(), r.y() + 7);
    34.  
    35. // Upper left
    36. path.lineTo(r.x() + 1, r.y() + 6);
    37. path.lineTo(r.x() + 1, r.y() + 5);
    38.  
    39. path.lineTo(r.x() + 5, r.y() + 1);
    40. path.lineTo(r.x() + 6, r.y() + 1);
    41. path.lineTo(r.x() + 7, r.y());
    To copy to clipboard, switch view to plain text mode 

    Here is my paint event and my resize event on my main widget :

    Qt Code:
    1. void ZeMessengerWindow::paintEvent(QPaintEvent * event)
    2. {
    3. QPainter painter(this);
    4. //painter.setRenderHint(QPainter::Antialiasing, true);
    5.  
    6. QPen pen;
    7. pen.setBrush(ZeStyle::get()->getBorderColor());
    8. painter.setPen(pen);
    9.  
    10. painter.setBrush(QColor(0, 0, 0, 0));
    11.  
    12. QRect rectBack(rect().x(), rect().y(),
    13. rect().width() - 1, rect().height() - 1);
    14.  
    15. ZePainterController::get()->DrawRoundRect(painter, rectBack);
    16. }
    17.  
    18. //=============================================================================
    19. //=============================================================================
    20.  
    21. void ZeMessengerWindow::resizeEvent(QResizeEvent * event)
    22. {
    23. setMask(QRegion(ZePainterController::get()->DrawRoundRect(rect()).toFillPolygon().toPolygon()));
    24. }
    To copy to clipboard, switch view to plain text mode 



    The top corners are working fine, unfortunately I have the following bug on the lower corners :

    Top :


    Bottom :


    It's like the mask was antialiased or something

Similar Threads

  1. Change shape of window / animate window
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2007, 08:16
  2. Popup window with round borders
    By anderssonj in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2007, 19:45
  3. Regarding drawing on Transparent Window
    By Shalabh in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2007, 10:32
  4. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  5. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21

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.