Results 1 to 15 of 15

Thread: Widget with rounded edges

  1. #1
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Widget with rounded edges

    I have an image for my startup window (shown, when app loads some stuff), that have rounded egdes (stylish, you know). By rounded edges I mean, that an image is of course rectangular as a whole, but what is seen in the image (a frame with app name, author, version) has rounded edges. Is there any trick to display it and keep those rounded edges, which means creating widget with rounded edges?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Widget with rounded edges

    Sure - QWidget::setMask() together with QSplashScreen probably.

  3. The following 2 users say thank you to wysota for this useful post:

    gruszczy (18th February 2009), tituslup (27th May 2009)

  4. #3
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget with rounded edges

    This is cool and looks cool! Thanks

    One more question: I've put my splashscreen into a widget, to make about window. Setting mask works fine, but I still have frame and top bar with -,x and title etc.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Widget with rounded edges

    You have to use setMask() on the top level window. And if you want to get rid of the title bar, set Qt::FramelessWindowHint on the window.

    By the way, don't use the splash screen if you don't intend to make it a window, use a regular widget instead.

  6. The following user says thank you to wysota for this useful post:

    gruszczy (18th February 2009)

  7. #5
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget with rounded edges

    Works perfectly! Thanks a lot :-)

  8. #6
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget with rounded edges

    i have a similar requirement. I have a rectangular window with a transparent background. The transparent background has rounded corners. When i run the application the window corners are not rounded.
    Do i need to use setMask? If yes, then how to use setMask exactly?

  9. #7
    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: Widget with rounded edges

    What Qt version are you using ?
    From 4.5 there is a new attribute Qt::WA_TranslucentBackground , try to set it and see if things get better

  10. #8
    Join Date
    Dec 2008
    Posts
    68

    Default Re: Widget with rounded edges

    My splashscreen has no background. If I would like to have the splashscreen to be half transparent, could you let me know what to do?

    I tried the above Qt::WA_TranslucentBackground, my splashscreen window is all black ...


    Thank you!
    Last edited by richardander; 9th March 2009 at 08:51.

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Widget with rounded edges

    Did you try using setMask()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #10
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget with rounded edges

    Quote Originally Posted by aamer4yu View Post
    What Qt version are you using ?
    From 4.5 there is a new attribute Qt::WA_TranslucentBackground , try to set it and see if things get better
    I am using Qt 4.4. I think even using Qt::WA_TranslucentBackground won't help as richardander mentioned that his splash screen window has gone all black after using this attribute.

    I think this is a generic problem in Qt4+ versions. Before Qt 4, it was possible to make top level window transparent and also have rounded edges, With Qt 4+, everything is dependent on X11 so X11 needs to have the composite extention then only you can achieve transparency and rounded corners in top level window.

    In my case, i have a transparent png with rounded corners which i use as the top level window background. When i run my application above a terminal or black background, i can see the rounded edges but otherwise i don't see rounded edges as the window manager fills the black color in the window corners, so the rounded corners can be seen only against the black background.

    Don't know what could be a workaround for this problem. Maybe, i'll get a png with rounded corners. and instead of transparent corners, the corners will be filled with the same color as my background application so it'll appear to have rounded corners.

    Is it possible to use setMask on a top level window so that it appears to have rounded corners?

    Edit: just read in this thread that @gruszczy was able to have rounded corners in the top level window using setMask. Can someone please post a sample code for setMask. I don't have any idea about setMask.
    Last edited by montylee; 9th March 2009 at 18:09.

  13. #11
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget with rounded edges

    I managed to get rounded corners on a top-level window using setMask. Here's the code for the same:

    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QLabel* label = new QLabel();
    5.  
    6. QPixmap pixmap("background.png");
    7. label->setPixmap(pixmap);
    8. label->setMask(pixmap.mask());
    9.  
    10. label->setFixedSize(pixmap.width(), pixmap.height());
    11. label->setWindowFlags(Qt::FramelessWindowHint);
    12. label->move(100, 100);
    13. label->show();
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    The background.png is transparent and has rounded corners and when i run the application, i can see rounded corners properly.

    Now, the problem is how to integrate this in my code? In the above example, label is the main application widget which acts as a window, so it displays rounded image properly.
    In my code, i have a custom class derived from QWidget and i display that widget using show() function. Now, when i put the above code in the constructor of my custom class, i get the background but i don't get rounded corners properly. I can see the rounded corners but the corners get filled with white color and the application appears to have rectangular corners.

    Am i setting the background of my application window properly. Is this the proper way of setting background image of a window. Here's what i am doing:

    1) Create a QLabel in the contructor of my class.
    2) Set a background image on the QLabel.
    3) Resize the QLabel to be of same size as that of the background image.
    4) Resize the application window to be of same size as that of background image.
    Here's the code i have:

    Qt Code:
    1. m_pbackgroundLabel = new QLabel(this);
    2. m_pbackgroundLabel->setPixmap(m_pmAlbum);
    3. m_pbackgroundLabel->setMask(m_pmAlbum.mask());
    4. m_pbackgroundLabel->setFixedSize(m_pmAlbum.width(), m_pmAlbum.height());
    5.  
    6. // Set the window size to be same as the backround image size
    7. setFixedSize(m_pmAlbum.width(), m_pmAlbum.height());
    To copy to clipboard, switch view to plain text mode 
    m_pmAlbum contains the background image and is of type QPixmap.

    Using setMask doesn't make a diference in my application although it works in the sample application i posted.

  14. #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: Widget with rounded edges

    Sorry, I didnt pay attention that you are using X11...
    Qt::WA_TranslucentBackground was meant for windows I guess.. still if i get time, will try this rounded edge thing...

  15. #13
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget with rounded edges

    i'll try to post a working example which reproduces my issue.
    If anybody has an idea about this please post...

  16. #14
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget with rounded edges

    ok, i was able to make my application's window corners round
    In the code which i posted, i was setting the mask of the QLabel which was incorrect.
    I had to set the mask of the application window and it worked.

  17. #15
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Widget with rounded edges

    Has any boys tried this in 4.5.1,

    I use 4.5.0 and when I use Qt::WA_TranslucentBackground and I get a black screen for my splash? any body can help?

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 20:39
  3. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  4. Toplevel widget with rounded corners.
    By munna in forum Qt Programming
    Replies: 7
    Last Post: 18th August 2006, 20:46
  5. widget with rounded corners
    By sreedhar in forum Qt Programming
    Replies: 4
    Last Post: 7th June 2006, 12:18

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.