Results 1 to 4 of 4

Thread: Qwt_Slider, how to create hot spots in its scale?

  1. #1
    Join Date
    Feb 2010
    Location
    Cuba
    Posts
    35
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Post Qwt_Slider, how to create hot spots in its scale?

    Hello!
    I need help in what follows: I'm using Qwt library, specifically its slider. I need to change the backgroud color to its scale. At first, I need to know at least how to do this, so that perhaps I get to do what I really want, that is creating hot zones in the scale. I explain: I need to divide the scale into zones, matching, for example, green color to values between 0 and 60, yellow between 61-90 and so on. I'm trying to develop graphic components for a configuration editor of a SCADA. I'm using QT and Qwt. Any help is welcomed.

    Thanks in advance.
    Last edited by Hogwarts; 18th February 2010 at 22:13.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt_Slider, how to create hot spots in its scale?

    You have to overload QwtSlider:aintEvent() ( or another virtual draw method ). Here you have to calculate your rectangles and fill them with a color using QPainter.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    Hogwarts (25th March 2010)

  4. #3
    Join Date
    Feb 2010
    Location
    Cuba
    Posts
    35
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qwt_Slider, how to create hot spots in its scale?

    I have implemented a class that inherits from QwtScaleDraw, in order to overwrite the method draw, to be used in the hot zones in the scale, but it seems that I can't use an object of this class, in the method setScaleDraw(QwtScaleDraw*) of another class that I implement, that inherits from QwtSlider, anyway, as I've been using this library from a little while, it is difficult for me. Could you give me a more specific indication? Thanks.

  5. #4
    Join Date
    Feb 2010
    Location
    Cuba
    Posts
    35
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Smile Re: Qwt_Slider, how to create hot spots in its scale?...one solution

    There are several solutions to the subject in question, this is what I found most suitable:

    I overloaded the function QwtSlider::PaintEvent() as follows:

    void CustomSlider:aintEvent(QPaintEvent *event)
    {
    const QRect &ur = event->rect();
    if ( ur.isValid() )
    {
    #if QT_VERSION < 0x040000
    QwtPaintBuffer paintBuffer(this, ur);
    draw(paintBuffer.painter(), ur);
    #else
    QPainter painter(this);
    if(editHotZones())
    drawHotZones(&painter);
    draw(&painter, ur);

    #endif
    }
    }

    the only thing new here is:

    if(editHotZones())
    drawHotZones(&painter);

    drawHotZones is a function used to draw zones with differents colors and ranges:

    void CustomSlider::drawHotZones(QPainter* painter)
    {
    QRect r;
    if(orientation() == Qt::Horizontal)
    {
    if(scalePosition() == TopScale)
    {

    r.setRect(scaleDraw()->scaleMap().transform(startHotZone1()),
    scaleDraw()->pos().y() - zoneHeight(),
    scaleDraw()->scaleMap().transform(endHotZone1()) - scaleDraw()->scaleMap().transform(startHotZone1()),
    zoneHeight());
    painter->fillRect(r, colorZone1());

    r.setRect(scaleDraw()->scaleMap().transform(endHotZone1()),
    scaleDraw()->pos().y() - zoneHeight(),
    scaleDraw()->scaleMap().transform(endHotZone2()) - scaleDraw()->scaleMap().transform(endHotZone1()),
    zoneHeight());
    painter->fillRect(r, colorZone2());

    r.setRect(scaleDraw()->scaleMap().transform(endHotZone2()),
    scaleDraw()->pos().y() - zoneHeight(),
    scaleDraw()->scaleMap().transform(customMaxValue()) - scaleDraw()->scaleMap().transform(endHotZone2()),
    zoneHeight());
    painter->fillRect(r, colorZone3());
    }
    (...)

    }


    I hope will be helpful, if you need to do something similar

Similar Threads

  1. QPaint - Scale
    By jsmith in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2009, 08:10
  2. logarithmic scale
    By Times in forum Qwt
    Replies: 2
    Last Post: 1st July 2008, 15:41
  3. Circular scale
    By fruzzo in forum Qwt
    Replies: 1
    Last Post: 6th March 2008, 07:20
  4. QSystemTrayIcon does not scale on X11
    By bleucanard in forum Qt Programming
    Replies: 0
    Last Post: 3rd March 2008, 09:35
  5. qwt 5 log scale..
    By halberdier83 in forum Qwt
    Replies: 7
    Last Post: 12th November 2007, 07:21

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.