The Ultimate Qt Community site
Home News Forum Wiki Contest FAQ Links

Go Back   Qt Centre Forum > Qt > Qt Programming

Qt Programming General Qt programming issues.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 23rd November 2007, 13:20
bunjee's Avatar
bunjee bunjee is offline
Advanced user
 
Join Date: Jan 2007
Location: Paris
Qt products used: Qt4
Qt platforms used: MacOS , Windows
Posts: 340
Thanks: 72
Thanked 1 Time in 1 Post
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
2
3
4
5
QRect maskRect(rect().x() + 1, rect().y() + 1, 
            rect().width() - 1, rect().height() - 1);
 
setMask(QRegion(ZePainterController::get()->DrawRoundRect(maskRect,
                    2000 / maskRect.width(), 2000 / maskRect.height()).toFillPolygon().toPolygon()));
Don't know If I should use a mask bitmap ?

Last edited by bunjee; 23rd November 2007 at 14:33.
Reply With Quote
  #2  
Old 25th November 2007, 11:20
bunjee's Avatar
bunjee bunjee is offline
Advanced user
 
Join Date: Jan 2007
Location: Paris
Qt products used: Qt4
Qt platforms used: MacOS , Windows
Posts: 340
Thanks: 72
Thanked 1 Time in 1 Post
Default Re: Round window

Anybody has a code snipet for this ?
Reply With Quote
  #3  
Old 25th November 2007, 12:03
Uwe Uwe is offline
Advanced user
 
Join Date: Feb 2006
Location: Munich, Germany
Qt products used: Qt3 , Qt4 , Qt/Embedded , Qtopia
Qt platforms used: MacOS , Unix/X11 , Windows
Posts: 452
Thanks: 0
Thanked 94 Times in 88 Posts
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
Reply With Quote
  #4  
Old 25th November 2007, 13:51
marcel marcel is offline
Expert
 
Join Date: Feb 2006
Location: Romania
Qt products used: Qt4
Qt platforms used: Unix/X11 , Windows
Posts: 2,744
Thanks: 8
Thanked 518 Times in 512 Posts
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.
Reply With Quote
  #5  
Old 25th November 2007, 20:23
bunjee's Avatar
bunjee bunjee is offline
Advanced user
 
Join Date: Jan 2007
Location: Paris
Qt products used: Qt4
Qt platforms used: MacOS , Windows
Posts: 340
Thanks: 72
Thanked 1 Time in 1 Post
Default Re: Round window

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

Qt Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
QPainterPath path;
 
    path.moveTo(r.x() + 7, r.y());
    path.lineTo(r.x() + r.width() - 7, r.y());
 
    // Upper right
    path.lineTo(r.x() + r.width() - 6, r.y() + 1);
    path.lineTo(r.x() + r.width() - 5, r.y() + 1);
 
    path.lineTo(r.x() + r.width() - 1, r.y() + 5);
    path.lineTo(r.x() + r.width() - 1, r.y() + 6);
    path.lineTo(r.x() + r.width(), r.y() + 7);
 
    path.lineTo(r.x() + r.width(), r.y() + r.height() - 7);
 
    // Lower right
    path.lineTo(r.x() + r.width() - 1, r.y() + r.height() - 6);
    path.lineTo(r.x() + r.width() - 1, r.y() + r.height() - 5);
 
    path.lineTo(r.x() + r.width() - 5, r.y() + r.height() - 1);
    path.lineTo(r.x() + r.width() - 6, r.y() + r.height() - 1);
    path.lineTo(r.x() + r.width() - 7, r.y() + r.height());
    
    path.lineTo(r.x() + 7, r.y() + r.height());
 
    // Lower left
    path.lineTo(r.x() + 6, r.y() + r.height() - 1);
    path.lineTo(r.x() + 5, r.y() + r.height() - 1);
 
    path.lineTo(r.x() + 1, r.y() + r.height() - 5);
    path.lineTo(r.x() + 1, r.y() + r.height() - 6);
    path.lineTo(r.x(), r.y() + r.height() - 7);
 
    path.lineTo(r.x(), r.y() + 7);
 
    // Upper left
    path.lineTo(r.x() + 1, r.y() + 6);
    path.lineTo(r.x() + 1, r.y() + 5);
 
    path.lineTo(r.x() + 5, r.y() + 1);
    path.lineTo(r.x() + 6, r.y() + 1);
    path.lineTo(r.x() + 7, r.y());
Here is my paint event and my resize event on my main widget :

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


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
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 03:39.


Powered by vBulletin Version 3.7.4 Copyright ©2000 - 2009, Jelsoft Enterprises Ltd., vRewrite 1.5 SEOed URLs completed by Tech Help Forum and Chalo Na.
© 2006–2009 Qt Centre - The Ultimate Qt Community site
Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.