Results 1 to 6 of 6

Thread: Related QLinearGradient

  1. #1
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    46
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Related QLinearGradient

    Hi to all

    I m painting a rectangle in QGraphicsItem by QLinearGradient ..
    But it is not working properly but same code i run on QWidget paint event then it
    is perfect ,..

    Pls tell me how can i use QLinearGradient in QGraphicsItem .

    Qt Code:
    1. QPainter painter(this);
    2. QLinearGradient linearGradient(0, 0, 100, 100);
    3. linearGradient.setColorAt(0.0, Qt::white);
    4. linearGradient.setColorAt(1.0, QColor(253,85,85));
    5. //linearGradient.setColorAt(1.0, Qt::black);
    6. painter.setBrush(linearGradient);
    7. painter.drawRect( 50,50,100,100);
    To copy to clipboard, switch view to plain text mode 

    Pls tell me
    Last edited by jpn; 25th May 2008 at 08:34. Reason: missing [code] tags
    Ashish Kumar Saryar

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Related QLinearGradient

    How about attaching a couple of screenshots to make "is not working" have some meaning...
    J-P Nurmi

  3. #3
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    46
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Related QLinearGradient

    hi,
    Actually i need to fill the rectangle with some gradient effects.
    It is basically a QgraphicsItem which i have added to QgraphicsScene.
    I have seen some examples and demos which has shown how to paint with gradeint effects.
    But thing is that none of the example is related to QgraphicsItem.

    I am trying to have gradient affects in a way shown in first post.But the it fills all the rectangle with second color i.e QColor(253,85,85).

    If u know the solution please guide where i m wrong.

    regards,
    ashish
    Ashish Kumar Saryar

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Related QLinearGradient

    And it's totally irrelevant to show us how you attempt to do it, right?

    Qt Code:
    1. void paint(...)
    2. {
    3. const QRectF bounds = boundingRect();
    4. QLinearGradient linearGradient(bounds.topLeft(), bounds.bottomRight());
    5. linearGradient.setColorAt(0.0, Qt::white);
    6. linearGradient.setColorAt(1.0, QColor(253,85,85));
    7. //linearGradient.setColorAt(1.0, Qt::black);
    8. painter->setBrush(linearGradient);
    9. painter->drawRect(bounds);
    10. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    46
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Related QLinearGradient

    Thanks ..

    Now it is working ..

    Pls tell me what i have done wrong earlier ....

    I have also given the point (0,0) and bounding rect width and height ..

    Pls tell me how it is working ..

    Really thanks a lot .
    Ashish Kumar Saryar

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Related QLinearGradient

    Quote Originally Posted by ashishsaryar View Post
    Pls tell me what i have done wrong earlier ....
    How could we? You didn't even show the code for a graphics item, just for a widget...
    J-P Nurmi

Similar Threads

  1. Related To Control Tranfer
    By ashishsaryar in forum Qt Programming
    Replies: 1
    Last Post: 3rd May 2008, 20:10
  2. Related To QGraphicsItemGroup
    By ashishsaryar in forum Qt Programming
    Replies: 0
    Last Post: 29th April 2008, 14:55
  3. QLinearGradient question
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 16:52
  4. Replies: 4
    Last Post: 3rd April 2006, 08:22
  5. Qt related questions and thoughts about getting job
    By AlexKiriukha in forum General Discussion
    Replies: 4
    Last Post: 26th January 2006, 12:25

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.