Results 1 to 10 of 10

Thread: How to draw a circle with spinbox coordinates

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default Re: How to draw a circle with spinbox coordinates

    Not in MiWidget, but in SpinVariable.

    You do not emit a signal at the moment from SpinVariable.
    Sorry but I don't understand.
    I emit it right here, I think:

    Qt Code:
    1. QObject::connect(spin1, SIGNAL(valueChanged(int)), area, SLOT(setposicionX(int)));
    2. QObject::connect(spin2, SIGNAL(valueChanged(int)), area, SLOT(setposicionY(int)));
    To copy to clipboard, switch view to plain text mode 

    Right there, when the spinbox value is changed it should trigger the setposicion functions.

    Thanks for the help!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: How to draw a circle with spinbox coordinates

    There you only connect! In your class SpinVariable you have to add a signal forwarding as said:
    Qt Code:
    1. spinvariable::spinvariable(QWidget *parent) :
    2. QWidget(parent)
    3. {
    4. spinbox = new QSpinBox;
    5. label = new QLabel;
    6.  
    7. QHBoxLayout *layout = new QHBoxLayout;
    8.  
    9. layout->addWidget(label);
    10. layout->addWidget(spinbox);
    11.  
    12. setLayout(layout);
    13. QObject::connect(spinbox, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
    14. }
    To copy to clipboard, switch view to plain text mode 
    The
    Qt Code:
    1. QObject::connect(spin1, SIGNAL(valueChanged(int)), area, SLOT(setposicionX(int)));
    To copy to clipboard, switch view to plain text mode 
    never came to action, since such a signal is never emitted!

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    Wiki edits
    20

    Default Re: How to draw a circle with spinbox coordinates

    Qt Code:
    1. spinvariable::spinvariable(QWidget *parent) :
    2. QWidget(parent)
    3. {
    4. spinbox = new QSpinBox;
    5. label = new QLabel;
    6.  
    7. QHBoxLayout *layout = new QHBoxLayout;
    8.  
    9. layout->addWidget(label);
    10. layout->addWidget(spinbox);
    11.  
    12. setLayout(layout);
    13.  
    14. QObject::connect(spinbox, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
    15. }
    To copy to clipboard, switch view to plain text mode 

    Edit: too late again ;-)

  4. #4
    Join Date
    Nov 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default Re: How to draw a circle with spinbox coordinates

    Hi!

    It worked! Thank you very much.

    Now, I am a little confused. Why do I have to connect the valueChanged() signal of the spinbox to itself?
    Is it because I am using a PushButton to trigger and event?
    I mean, I've been reading and doing a lot of Qt tutorials and this is the first time I see that. I followed the cannonball tutorial to write my program and if you check it you'll see they don't do that. Whenever the slider is moved in their program, it updates the variable values in the cannonball drawing area.

    I thought that whenever a spinbox or a slider is changed, it emits its valueChanged() signal, and the only thing you have to do is to connect it to whatever you want to do.

    So if you please can clarify me that I'll appreciate.

    Thanks again!

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: How to draw a circle with spinbox coordinates

    You don't connect the signal to itself. To use a signal you need direct access to the object. In MiWidget you cant access your spinbox, you only can access your class spinvariable. It has a spinbox inside, but that don't matter, for the connect it is only a widget and a widget has no value changed signal. So you have to forward the signal. From the spinbox to the class spinvariable and from there to your MiWidget.

    Another option would be to declare a public pointer to your spinbox but that would be a bad design.

  6. The following user says thank you to Lykurg for this useful post:

    rdelgado (18th August 2010)

  7. #6
    Join Date
    Nov 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default Re: How to draw a circle with spinbox coordinates

    Hi,

    Now I see it, as you said, from the spinbox to the class, and from there to MiWidget!
    I get it now. In the others examples I looked, all the spinboxes and sliders where part of the same class.

    Thank you very much for the help. I'll keep learning!

Similar Threads

  1. To draw a circle on a frame when the key is pressed
    By soumya in forum Qt Programming
    Replies: 18
    Last Post: 9th February 2010, 10:21
  2. how to draw a circle on a frame in Qt-4
    By grsandeep85 in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2009, 08:05
  3. How to draw a special circle pie
    By parnedo in forum Qt Programming
    Replies: 7
    Last Post: 3rd July 2009, 15:25
  4. How to draw a semi circle or arc of ellipse
    By parnedo in forum Qt Programming
    Replies: 2
    Last Post: 2nd July 2009, 01:39
  5. What is the fastest way to draw a circle ?
    By Vladimir in forum Qt Programming
    Replies: 18
    Last Post: 6th September 2007, 17:26

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.