Results 1 to 4 of 4

Thread: QPushButton set width and height from StyleSheet

  1. #1
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default QPushButton set width and height from StyleSheet

    Hello,
    I am loading a background image in a QPushButton and I would like to set the button width and height from the stylesheet with the background image width and height. Is it possible?

    Qt Code:
    1. QPushButton *btn = new QPushButton("click me",0);
    2. style = "QPushButton { ";
    3. style += "background: url(:/images/btn-orange-normal.png);";
    4. style += "background-repeat: repeat-n; border-width: 0px; border-style: none;";
    5.  
    6. /*
    7. I would like to add something like:
    8. style += "width: background.width; height: background.height"
    9. */
    10.  
    11. style += "}";
    12. btn->setStyleSheet(style);
    To copy to clipboard, switch view to plain text mode 

    Tx a lot,

  2. #2
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QPushButton set width and height from StyleSheet

    QPushButton::indicator
    {
    width: 20px;
    height: 20px;
    }

  3. #3
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QPushButton set width and height from StyleSheet

    this will set the button width and height to 20 px ... I would like to have the same width and height of the btn-orange-normal.png

  4. #4
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: QPushButton set width and height from StyleSheet

    Oh sorry..So you wish to strecth your .png file to fit the button background?

    What about adding "background-position: top-left;"?

Similar Threads

  1. problems with getting height and width of widget
    By martinn in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2010, 03:04
  2. QLayout: different SizeConstraints for width and height?
    By PhilippB in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2009, 16:33
  3. Replies: 1
    Last Post: 18th February 2009, 08:34
  4. Pixmap height / width without loading it
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 07:10
  5. width and height of QTabWidget
    By chikkireddi in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 13:53

Tags for this Thread

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.