Results 1 to 3 of 3

Thread: Left-to-right gradient with proper anchoring

  1. #1
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Left-to-right gradient with proper anchoring

    How would I do a left-to-right gradient for a rectangle that should use
    anchors.fill: parent
    for positioning?

    The only "trick" for left-to-right gradient fill I have found so far has been to rotate the whole rectangle, but this (obviously) does more than I want. Obviously, the anchoring is calculated before the rectangle is rotated, not after, because it appears geometrically rotated.

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

    Default Re: Left-to-right gradient with proper anchoring

    If you are still looking for a solution to this problem, would you consider explaining better what the problem is? You don't know how to make a linear gradient or is it something else?
    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.


  3. #3
    Join Date
    Nov 2010
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Left-to-right gradient with proper anchoring

    I have not found a solution to this problem myself. But examples that illustrate the problem are as following.

    A vertical gradient, anchored to parent. All is normal here.
    Qt Code:
    1. import Qt 4.7
    2.  
    3. Rectangle {
    4. width: 800
    5. height: 600
    6. id: mainContainer
    7. color: "red"
    8.  
    9. Rectangle {
    10. anchors.margins: 10
    11. anchors.fill: parent
    12. gradient: Gradient {
    13. GradientStop { position: 0.0; color: "black" }
    14. GradientStop { position: 0.5; color: "white" }
    15. GradientStop { position: 1.0; color: "black" }
    16. }
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    But now if you would like to have a horizontal gradient, you would be forced to rotate the rectangle. But the result is not what one would expect:
    Qt Code:
    1. import Qt 4.7
    2.  
    3. Rectangle {
    4. width: 800
    5. height: 600
    6. id: mainContainer
    7. color: "red"
    8.  
    9. Rectangle {
    10. anchors.margins: 10
    11. anchors.fill: parent
    12. rotation: 270
    13. gradient: Gradient {
    14. GradientStop { position: 0.0; color: "black" }
    15. GradientStop { position: 0.5; color: "white" }
    16. GradientStop { position: 1.0; color: "black" }
    17. }
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    I attached snapshots of the painted result of posted example QML.

    EDIT: Also there seems to be a bug report of similar nature -> QTBUG-10644
    Attached Images Attached Images
    Last edited by ristiisa; 9th November 2010 at 08:21.

Similar Threads

  1. Rotating Gradient
    By JeffC in forum Newbie
    Replies: 3
    Last Post: 3rd June 2012, 12:11
  2. Replies: 4
    Last Post: 29th August 2010, 19:16
  3. getting gradient colors
    By venkat.godavarthi in forum Qt Programming
    Replies: 1
    Last Post: 30th October 2009, 14:36
  4. Gradient in histogram
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 1st August 2009, 12:48
  5. QPainter Gradient
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 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.