Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Translation from stylesheet gradient to gradient class
Qt 6.11 is out! See what's new in the release blog

[Solved] Translation from stylesheet gradient to gradient class

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janfaroe
    wrote on last edited by
    #1

    Hi all,

    I used to have a rectangle having its background painted with a qlineargradient in a stylesheet, but I had to move the painting to an item delegate. However, trying to translate the stylesheet syntax into a QLinearGradient instance don't work properly for me; I simply see no gradient, only evenly distributed background color.

    The stylesheet gradient definition: qlineargradient(spread:pad, x1:1, y1:1, x2:1, y2:0.057727, stop:0 #7B99BB, stop:1 #9CB6D5 )

    My attempt to translate into QLinearGradient:

    @QLinearGradient gradient(1.0, 1.0, 1.0, 0.057727);
    gradient.setSpread(QLinearGradient::PadSpread);
    gradient.setColorAt(0, QColor("#7B99BB"));
    gradient.setColorAt(1, QColor("#9CB6D5"));@

    (And of course the painting of the rect hereafter).

    Can anybody point me in a direction that actually might work?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      janfaroe
      wrote on last edited by
      #2

      Seems like the gradient needs to have

      @gradient.setCoordinateMode(QLinearGradient::ObjectBoundingMode);@

      when constructed with start and stop points instead of coordinates.

      How obvious! [/sarcasm]

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved