Results 1 to 6 of 6

Thread: QSlider problem

  1. #1
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QSlider problem

    Hi,

    I am a newbie in Qt. I am trying to use QSlider to control the color of a 3D volume. But I having a hard time figuring it out. This is what I am doing or trying to do:
    This is only a part of my code-

    Qt Code:
    1. int mvar1;
    2. QSlider *slider = new QSlider(Qt::Horizontal);
    3. slider->setMinimum(1);
    4. slider->setMaximum(100);
    5. if(slider has moved )
    6. {
    7. myvar1 = get new value of slider; // this value then goes into another function to control the color
    8. }
    To copy to clipboard, switch view to plain text mode 

    Can anyone guide me how to do this without using signals and slots? How do I figure out if the slider has moved? Is there a function that gives me the status of the slider? I went through the documentation but had a hard time understanding it. What is the easiest way of doing this?

    Thanks,
    Ashish
    Last edited by wysota; 11th December 2006 at 23:07. Reason: missing [code] tags

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

    Default Re: QSlider problem

    The easiest way of doing this is signals and slots
    Simply make that "another function to control the color" a slot and connect it to the slider's signal.

  3. #3
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSlider problem

    Thanks for replying wysota.
    With signals and slots, the sender and receiver should be pointers to QObject, right. Now my color variable goes to a function that is a part of another class which is a part of completely different API(VTK). I am using 2 different APIs in the same application, Qt and VTK. The function to control color looks like-AddRGB(r,g,b) and r is the value that I want to control with the slider. But this AddRGB function is a part of the VTK API.

    In this case how do I do it?

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

    Default Re: QSlider problem

    Create a dummy QObject which will simply call your actual method, like this:
    Qt Code:
    1. class SignalProxy : public QObject {
    2. Q_OBJECT
    3. public:
    4. SignalProxy(VTKObject *o, QObject *parent=0) : QObject(parent){
    5. _o = o;
    6. }
    7. public slots:
    8. void receive(int value){
    9. if(!_o) return;
    10. o->doSomething(value);
    11. }
    12. private:
    13. VTKObject *_o;
    14. };
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Oct 2006
    Location
    USA
    Posts
    23
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSlider problem

    Thanks wysota.
    So how would my connect function look then?
    would it be-
    connect(slider, SIGNAL(valuechanged(int)), mysignalproxy, SLOT(dosomething(value)) );

    where-mysignalproxy is a pointer to SignalProxy
    and function dosomething(value) would take the new value and call AddRGB(value,g,b) within it.
    Is this how it works, to make sure I understand it, correctly?

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

    Default Re: QSlider problem

    Yes, you understand it correctly. Just remember that the signal is called "valueChanged", not "valuechanged". Also remember that connect() is a method of QObject, so you'll probably have to call it as QObject::connect or mysingalproxy->connect as you'll probably be doing it from outside of any QObject.

Similar Threads

  1. QSlider Update Problem
    By December in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2006, 04:02
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.