Results 1 to 7 of 7

Thread: QPushButton -- Round shape

  1. #1
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb QPushButton -- Round shape

    Hi,

    I am using QT 4.1 on windows
    I want to my button as round shape (Based on image type).



    Please help me!!!

  2. #2
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QPushButton -- Round shape

    It can be simply achieved with style sheets:
    Qt Code:
    1. button->setStyleSheet("
    2. border-image: url(button.png) 3 10 3 10;
    3. border-top: 3px transparent;
    4. border-bottom: 3px transparent;
    5. border-right: 10px transparent;
    6. border-left: 10px transparent;
    7. ");
    To copy to clipboard, switch view to plain text mode 
    Sample from Qt Documentation. More here: http://doc.trolltech.com/4.6/stylesheet.html
    Oleg Shparber

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPushButton -- Round shape

    You can also use QWidget::setMask().

  4. #4
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton -- Round shape

    hi I have tried with your example but still its n not working ..here is my code

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QPushButton *button = new QPushButton();
    button->setStyleSheet("border-image: url(:/button.png) 3 10 3 10;border-top: 3px transparent;border-bottom: 3px transparent; border- right: 10px transparent;border-left: 10px transparent;");
    button->show();
    return app.exec();
    }
    button.png is in my application folder and in debug folder also....

  5. #5
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton -- Round shape

    Hi I have tried this example ..but its not working ... Button.png is in my App folder and debug folder also...
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QLabel topLevelLabel;
    QPixmap pixmap(":/button.png");
    topLevelLabel.setPixmap(pixmap);
    topLevelLabel.setMask(pixmap.mask());
    topLevelLabel.show();
    return app.exec();
    }

  6. #6
    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: QPushButton -- Round shape

    You could refer to the shaped clock example in Qt Demo,,, instead of the widget, you can have QPushButton.

  7. #7
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPushButton -- Round shape

    you have provided the wrong path to button.png.

    ":/button.png" means the file is located in the qt resource file and not the current/debug dir.

Similar Threads

  1. round double
    By wirasto in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2009, 09:32
  2. Customise QPushButton shape
    By ataffard in forum Qt Programming
    Replies: 3
    Last Post: 22nd March 2008, 07:02
  3. Round window
    By bunjee in forum Qt Programming
    Replies: 4
    Last Post: 25th November 2007, 21:23
  4. Round QSlider
    By Havard in forum Qt Programming
    Replies: 5
    Last Post: 25th June 2007, 21:14
  5. Replies: 3
    Last Post: 26th September 2006, 13:16

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.