Results 1 to 8 of 8

Thread: How to set border for QPushButton?

  1. #1
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default How to set border for QPushButton?

    I have a QPushButton and would like to put a red border around it with a certain thickness. What's the best way to do this?

  2. #2
    Join Date
    Aug 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: How to set border for QPushButton?

    right-click it and then "Change styleSheet...", then you can use css to set border.
    try this:

    border: 1px solid red;

  3. #3
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to set border for QPushButton?

    How would I do it with C++ code?

  4. #4
    Join Date
    Jul 2008
    Location
    London, UK
    Posts
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set border for QPushButton?

    Hiya,

    p_myPushButton = QPushButton("MyButton", p_parent);
    p_myPushButton->setStyleSheet("border:5px solid #ff0000;");

    That should do it.

    Yours,
    Matthew.

  5. #5
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to set border for QPushButton?

    setStyleSheet() doesn't exist for QPushButton... am I missing something?

  6. #6
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to set border for QPushButton?


  7. #7
    Join Date
    Jul 2008
    Location
    London, UK
    Posts
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to set border for QPushButton?

    Quote Originally Posted by DiamonDogX View Post
    setStyleSheet() doesn't exist for QPushButton... am I missing something?
    Sure it does. It inherits the setStyleSheet member function from QWidget via QAbstractButton.

    Good luck!
    Matthew.

  8. #8
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to set border for QPushButton?

    I'm sorry, you are correct. My intellisense was messing up and throwing me off! Anyway, it does set the button's border, but it blanks out the button's background. I tried setting it again after the setStyleSheet call but it did not work, presumably because it's being overwritten by the style sheet settings. I understand I could use "background-color" in the style sheet instead, but is that the only way to do it? Thanks.

Similar Threads

  1. Tooltip has undesired border
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2009, 15:43
  2. Replies: 5
    Last Post: 14th April 2009, 08:27
  3. Showing QWidget border around the window
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2008, 20:14
  4. QPrinter on QGraphicsScene Border Problem
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 15:49
  5. How to create a movable border between two widgets?
    By Teuniz in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2007, 08:45

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.