Results 1 to 5 of 5

Thread: Need help associating values to a widget.

  1. #1
    Join Date
    Dec 2015
    Posts
    4
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Need help associating values to a widget.

    Hello,
    I have a project for uni and i want to associate values (floats) to a visual widget.

    Let's say it's in percentage, where 0% is totally blue and 100% is totally green, what's in between varies between blue and green.

    It's a matrix and i want to associate it's values to create a blue square that starts to turn green with time, the c++ code is ready but i don't know much about GUI.

    Any idea how to it? what should i use to be able to form a square with my values and associate them to a colour?

    Thanks a lot

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Need help associating values to a widget.

    If you can create a QPixmap of the correct size containing your coloured square (QPainter) then you can simply display it in a QLabel. Once you can do that then animating a colour change becomes possible.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,324
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Need help associating values to a widget.

    Probably the easiest would be to create a QWidget, and implement the paintEvent() to fill the square with the current color. You create a QTimer to cycle through your colors. To change the current color, you would implement a slot connected to the timer's timeout signal. In this slot, you set the current color based on where you are in the color cycle, then call repaint() on the widget to trigger a new paint event.

    Or use ChrisW67's alternative approach.

  4. #4
    Join Date
    Dec 2015
    Posts
    4
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: Need help associating values to a widget.

    well i don't want to change the colour using paint event but i wan t to link each of values which are 100 different value to shades of blue/green. can it be done?

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,324
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Need help associating values to a widget.

    QGradient and QLinearGradient might help.

Similar Threads

  1. Replies: 1
    Last Post: 22nd April 2013, 23:42
  2. associating file with executable
    By avanindra in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2012, 07:27
  3. Associating QWidget with QProcess
    By in_dbasu in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2011, 15:22
  4. Replies: 3
    Last Post: 28th November 2010, 14:06
  5. Associating file extensions
    By fullmetalcoder in forum General Programming
    Replies: 9
    Last Post: 10th May 2006, 13:12

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
  •  
Qt is a trademark of The Qt Company.