Results 1 to 6 of 6

Thread: How to stretch background image used in brush-palette

  1. #1
    Join Date
    Dec 2008
    Posts
    13

    Default How to stretch background image used in brush-palette

    I am trying to make a header label with text over a background image. I'm using the image like a spacer image, so it should stretch the width of the label. I have been able to get the image in the background; however I can't figure out how to make it stretch. Here is the code:

    Qt Code:
    1. palette = QtGui.QPalette()
    2.  
    3. brush = QtGui.QBrush(QtGui.QColor(170, 255, 0))
    4. brush.setTexture(QtGui.QPixmap("Images/small_border.png"))
    5. brush.setStyle(QtCore.Qt.TexturePattern)
    6. palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
    7.  
    8. self.ui.label_2.setPalette(palette)
    To copy to clipboard, switch view to plain text mode 
    The image is being displayed in the TexturePattern, just as it should given the style. However I don't see a way to set the style so that it will stretch the image to fill the space. How can I do that?

    Thanks
    Last edited by jpn; 17th December 2008 at 17:50. Reason: missing [code] tags

  2. #2
    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: How to stretch background image used in brush-palette

    May be you can try QLabel::setScaledContents

  3. #3
    Join Date
    Dec 2008
    Posts
    13

    Default Re: How to stretch background image used in brush-palette

    I think that only applies to objects in the foreground. It works like I want it to if I load a picture into the label. The problem is that I can't get any text on top of it at that point because you have to pick one or the other.

  4. #4
    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: How to stretch background image used in brush-palette

    In that case, scale the pixmap to the label's size.
    Qt Code:
    1. QPixmap pix = QtGui.QPixmap("Images/small_border.png").scaled(label_2->size());
    2. brush.setTexture(pix);
    To copy to clipboard, switch view to plain text mode 

    Somethign like that.. hope u get the idea

  5. #5
    Join Date
    Dec 2008
    Posts
    13

    Default Re: How to stretch background image used in brush-palette

    I didn't know you could scale it like that, so I tried to scale it against the main centralWidget to give it a full backdrop. It's a case where I believe it's working properly but not as desired.

    When I scale it against the main frame it sizes it up properly to give a nice textured pattern of the image. However I can't find any way to make it not texture and just give me a solid image that is scaled to be the size of the widget.

    If I don't specify the texture than it will display the image in it's natural size. So if I wanted to use a background picture I can just make it larger than most monitors can display it, and I have my background image.

    However I've tried all kinds of ways but still can't find a way to make the image simply scale to the size of target widget. I've tried creating the brush with a pix image as the argument, but I guess it defaults to be a texture. Is putting an image into a Texture the only way to insert it into a brush, or is there any other way?

  6. #6
    Join Date
    Dec 2008
    Posts
    13

    Default Re: How to stretch background image used in brush-palette

    <bump> Is this functionality just not available in pyqt4?

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.