Results 1 to 11 of 11

Thread: problem with DoubleSpinBox

  1. #1
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with DoubleSpinBox

    Hi,
    i want when i finished entred position (numbers) in 3 doublespinbox
    it show to me an object
    for that

    i make like that, i define class
    Qt Code:
    1. Coordinate3dWidget::Coordinate3dWidget(QWidget *parent):
    2. QWidget(parent)
    3. {
    4.  
    5. pos_cam = new QGroupBox(this);
    6. pos_cam->setObjectName(QString::fromUtf8("pos_cam"));
    7. pos_cam->setGeometry(QRect(10, 50, 191, 71));
    8. pos_cam->setTitle("Position");
    9.  
    10. sbx_cam = new QDoubleSpinBox(pos_cam);
    11. sbx_cam->setObjectName(QString::fromUtf8("sbx_cam"));
    12. sbx_cam->setGeometry(QRect(10, 40, 51, 22));
    13. sbx_cam->setRange(-5000, 5000);
    14. lx_cam = new QLabel(pos_cam);
    15. lx_cam->setObjectName(QString::fromUtf8("lx_cam"));
    16. lx_cam->setGeometry(QRect(10, 20, 46, 13));
    17. lx_cam->setText(QApplication::translate("MainWindow", "X :", 0, QApplication::UnicodeUTF8));
    18.  
    19. sby_cam = new QDoubleSpinBox(pos_cam);
    20. sby_cam->setObjectName(QString::fromUtf8("sby_cam"));
    21. sby_cam->setGeometry(QRect(70, 40, 51, 22));
    22. sby_cam->setRange(-5000, 5000);
    23. ly_cam = new QLabel(pos_cam);
    24. ly_cam->setObjectName(QString::fromUtf8("ly_cam"));
    25. ly_cam->setGeometry(QRect(70, 20, 46, 13));
    26. ly_cam->setText(QApplication::translate("MainWindow", "Y :", 0, QApplication::UnicodeUTF8));
    27. sbz_cam = new QDoubleSpinBox(pos_cam);
    28. sbz_cam->setObjectName(QString::fromUtf8("sbz_cam"));
    29. sbz_cam->setGeometry(QRect(130, 40, 51, 22));
    30. sbz_cam->setRange(-5000, 5000);
    31. lz_cam = new QLabel(pos_cam);
    32. lz_cam->setObjectName(QString::fromUtf8("lz_cam"));
    33. lz_cam->setGeometry(QRect(130, 20, 46, 13));
    34. lz_cam->setText(QApplication::translate("MainWindow", "Z :", 0, QApplication::UnicodeUTF8));
    35.  
    36. connect(sbx_cam, SIGNAL(editingFinished()), this, SLOT(onCoordinateChanged()));
    37. connect(sby_cam, SIGNAL(editingFinished()), this, SLOT(onCoordinateChanged()));
    38. connect(sbz_cam, SIGNAL(editingFinished()), this, SLOT(onCoordinateChanged()));
    39. }
    To copy to clipboard, switch view to plain text mode 
    but it dos not work , it add to me 3 object (when i enter value in sbx_cam it add to me an object , when i enter value in sby_cam it add to me another !!!!!!!!!!!)
    i want when i the editingFinished() of the 3 DoubleSpinBox i add the object not when i finished one

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

    Default Re: problem with DoubleSpinBox

    Do yourself a favour and read about using layouts.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with DoubleSpinBox

    layout!! why layout ?
    Last edited by rimie23; 8th June 2012 at 22:09.

  4. #4
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with DoubleSpinBox

    Hi
    i do not use layout her
    i just use groupbox

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

    Default Re: problem with DoubleSpinBox

    Quote Originally Posted by dreamvig View Post
    i do not use layout her
    Yes, I can see that.

    i just use groupbox
    No, you don't. And even if you did, you'd still need layouts.

    As a test, use this main() with your Coordinate3dWidget class:

    Qt Code:
    1. int main(int argc, char **argv) {
    2. QApplication app(argc, argv);
    3. Coordinate3dWidget w;
    4. QFont f;
    5. f.setPointSize(72);
    6. w.setFont(f);
    7. w.show();
    8. Coordinate3dWidget w2;
    9. f.setPointSize(4);
    10. w2.setFont(f);
    11. w2.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    How does it look? I hope this answers rimie23's question as well. Conclusions are yours to draw.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with DoubleSpinBox

    i don't undertand what you want by this exemple

    maybe you do not understand where is my problem exactelly

    because i make in my mainwindow like that
    Qt Code:
    1. ogreWidget = new OgreWidget(this);
    2. setCentralWidget(ogreWidget);
    3. page_14 = new Coordinate3dWidget;
    4. onnect(page_14, SIGNAL(coordinateChanged(const Ogre::Vector3&)),
    5. ogreWidget, SLOT(setCameraPosition(const Ogre::Vector3&)));
    6. connect(ogreWidget, SIGNAL(cameraPositionChanged(const Ogre::Vector3&)),
    7. page_14, SLOT(setNewCoordinate(const Ogre::Vector3&)));
    To copy to clipboard, switch view to plain text mode 
    that mean i related it where i draw the object

    it just do net let me finishe entring in the three spinbox

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

    Default Re: problem with DoubleSpinBox

    Quote Originally Posted by dreamvig View Post
    i don't undertand what you want by this exemple
    Maybe if you ran it, you'd understand.

    maybe you do not understand where is my problem exactelly
    That's true, I don't, because you are describing your problem and then showing some code totally unrelated to that (and doing that again in this post).

    Since I can understand the code better than your words, I talk about problems with your code hoping (in vain, as we can see) that either you show some related code next time or fixing the problem I see will somehow influence your primary problem or at least the description of it. Currently your English is so bad I can't make up what you are talking about. I can only guess that you want a slot to be called after all three of the boxes are changed and not after each one gets a value but since you didn't show any code related to that, I'm just left with my guesses.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with DoubleSpinBox

    I am so sorry
    i know that my english is bad (it's not my native language )
    . I can only guess that you want a slot to be called after all three of the boxes are changed and not after each one gets a value but since you didn't show any code related to that, I'm just left with my guesses.
    yes that what i want ,i want "add object" when i enter numbers in the three boxes .

    I will give you all the code
    in my class Coordinate3dWidget.h i have like that
    Qt Code:
    1. class Coordinate3dWidget : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. Coordinate3dWidget(QWidget *parent=0);
    6. public slots:
    7. void setNewCoordinate(const Ogre::Vector3 &coordinate);
    8. signals:
    9. void coordinateChanged(const Ogre::Vector3 &coordinate);
    10. private slots:
    11. void onCoordinateChanged();
    12. private:
    13.  
    14. QDoubleSpinBox *sbx_cam;
    15. QLabel *lx_cam;
    16. QLabel *ly_cam;
    17. QDoubleSpinBox *sby_cam;
    18. QDoubleSpinBox *sbz_cam;
    19. QLabel *lz_cam;
    20. QGroupBox *pos_cam;
    21.  
    22. };
    To copy to clipboard, switch view to plain text mode 
    in Coordinate3dWidget.cpp
    Qt Code:
    1. #include <QLabel>
    2. #include <QHBoxLayout>
    3. #include <QToolButton>
    4. #include <QPushButton>
    5.  
    6. #include "coordinate3dwidget.h"
    7. #include"my_interface.h"
    8. //class MainWindow;
    9. Coordinate3dWidget::Coordinate3dWidget(QWidget *parent):
    10. QWidget(parent)
    11. {
    12.  
    13. pos_cam = new QGroupBox(this);
    14. pos_cam->setObjectName(QString::fromUtf8("pos_cam"));
    15. pos_cam->setGeometry(QRect(10, 50, 191, 71));
    16. pos_cam->setTitle("Position");
    17.  
    18. sbx_cam = new QDoubleSpinBox(pos_cam);
    19. sbx_cam->setObjectName(QString::fromUtf8("sbx_cam"));
    20. sbx_cam->setGeometry(QRect(10, 40, 51, 22));
    21. sbx_cam->setRange(-5000, 5000);
    22. lx_cam = new QLabel(pos_cam);
    23. lx_cam->setObjectName(QString::fromUtf8("lx_cam"));
    24. lx_cam->setGeometry(QRect(10, 20, 46, 13));
    25. lx_cam->setText(QApplication::translate("MainWindow", "X :", 0, QApplication::UnicodeUTF8));
    26.  
    27. sby_cam = new QDoubleSpinBox(pos_cam);
    28. sby_cam->setObjectName(QString::fromUtf8("sby_cam"));
    29. sby_cam->setGeometry(QRect(70, 40, 51, 22));
    30. sby_cam->setRange(-5000, 5000);
    31. ly_cam = new QLabel(pos_cam);
    32. ly_cam->setObjectName(QString::fromUtf8("ly_cam"));
    33. ly_cam->setGeometry(QRect(70, 20, 46, 13));
    34. ly_cam->setText(QApplication::translate("MainWindow", "Y :", 0, QApplication::UnicodeUTF8));
    35. sbz_cam = new QDoubleSpinBox(pos_cam);
    36. sbz_cam->setObjectName(QString::fromUtf8("sbz_cam"));
    37. sbz_cam->setGeometry(QRect(130, 40, 51, 22));
    38. sbz_cam->setRange(-5000, 5000);
    39. lz_cam = new QLabel(pos_cam);
    40. lz_cam->setObjectName(QString::fromUtf8("lz_cam"));
    41. lz_cam->setGeometry(QRect(130, 20, 46, 13));
    42. lz_cam->setText(QApplication::translate("MainWindow", "Z :", 0, QApplication::UnicodeUTF8));
    43.  
    44. connect(sbx_cam, SIGNAL(/*valueChanged*/editingFinished()), this, SLOT(onCoordinateChanged()));
    45. connect(sby_cam, SIGNAL(/*valueChanged*/editingFinished()), this, SLOT(onCoordinateChanged()));
    46. connect(sbz_cam, SIGNAL(/*valueChanged*/editingFinished()), this, SLOT(onCoordinateChanged()));
    47. }
    48.  
    49. void Coordinate3dWidget::setNewCoordinate(const Ogre::Vector3 &coordinate)
    50. {
    51. blockSignals(true);
    52. sbx_cam->setValue(coordinate.x);
    53. sby_cam->setValue(coordinate.y);
    54. sbz_cam->setValue(coordinate.z);
    55. blockSignals(false);
    56. }
    57.  
    58. void Coordinate3dWidget::onCoordinateChanged()
    59. {
    60. Ogre::Vector3 newCoord(sbx_cam->value(),
    61. sby_cam->value(),
    62. sbz_cam->value());
    63. emit coordinateChanged(newCoord);
    64. }
    To copy to clipboard, switch view to plain text mode 
    and in my mainwindow
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. ogreWidget = new OgreWidget(this);
    4. setCentralWidget(ogreWidget);
    5. createDockWidget();
    6.  
    7. }
    8. void MainWindow::createDockWidget()
    9. {
    10. page_14 = new Coordinate3dWidget;
    11. page_14->setGeometry(QRect(0, 0, 211, 250));
    12. connect(page_14, SIGNAL(coordinateChanged(const Ogre::Vector3&)),
    13. ogreWidget, SLOT(setCameraPosition(const Ogre::Vector3&)));
    14. connect(ogreWidget, SIGNAL(cameraPositionChanged(const Ogre::Vector3&)),
    15. page_14, SLOT(setNewCoordinate(const Ogre::Vector3&)));
    To copy to clipboard, switch view to plain text mode 
    in my class OgreWidget i defined slot
    Qt Code:
    1. public slots:
    2. void setCameraPosition(const Ogre::Vector3 &pos);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. in setCameraPosition: when i entre the numbers in the three boxes i must execute this slot to add object in the position entred
    2. void QOgreWidget::setCameraPosition(const Ogre::Vector3 &pos)
    3. {
    4.  
    5. CamNode= mSceneMgr->getRootSceneNode()->createChildSceneNode();
    6. ent_cam = mSceneMgr->createEntity( Ogre::SceneManager:: PT_CUBE);
    7. Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("green", "General");
    8. material->getTechnique( 0 )->getPass( 0 )->setAmbient(1, 1, 0);
    9. ent_cam->setMaterial(material);
    10. mSceneMgr->getRootSceneNode()->createChildSceneNode();
    11. CamNode->setPosition(pos);
    12. CamNode->attachObject(ent_cam);
    13.  
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: problem with DoubleSpinBox

    Ok, now the situation is clear.

    First of all please do consider using layouts in your widget and derive your widget from QGroupBox and not QWidget.

    Qt Code:
    1. Coordinate3dWidget::Coordinate3dWidget(QWidget *parent):
    2. QGroupBox(parent)
    3. {
    4. setTitle("Position");
    5. QGridLayout *l = new QGridLayout(this);
    6. lx_cam = new QLabel;
    7. sbx_cam = new QDoubleSpinBox;
    8. sbx_cam->setRange(-5000, 5000);
    9.  
    10. lx_cam->setText(tr("X"));
    11. l->addWidget(lx_cam, 0,0);
    12. l->addWidget(sbx_cam, 1, 0);
    13.  
    14. ly_cam = new QLabel;
    15. sby_cam = new QDoubleSpinBox;
    16. sby_cam->setRange(-5000, 5000);
    17. ly_cam->setText(tr("Y"));
    18. l->addWidget(ly_cam, 0,1);
    19. l->addWidget(sby_cam, 1, 1);
    20.  
    21. lz_cam = new QLabel;
    22. sbz_cam = new QDoubleSpinBox;
    23. sbz_cam->setRange(-5000, 5000);
    24. lz_cam->setText(tr("Z"));
    25. l->addWidget(lx_cam, 0,2);
    26. l->addWidget(sbz_cam, 1, 2);
    27.  
    28. connect(sbx_cam, SIGNAL(valueChanged(double)), this, SLOT(onCoordinateChanged()));
    29. connect(sby_cam, SIGNAL(valueChanged(double)), this, SLOT(onCoordinateChanged()));
    30. connect(sbz_cam, SIGNAL(valueChanged(double)), this, SLOT(onCoordinateChanged()));
    31. }
    To copy to clipboard, switch view to plain text mode 

    Isn't that clearer and doesn't it work better?

    Now for your main problem... here is how your "onCoordinateChanged()" which looks like:
    Qt Code:
    1. void Coordinate3dWidget::onCoordinateChanged()
    2. {
    3. Ogre::Vector3 newCoord(sbx_cam->value(),
    4. sby_cam->value(),
    5. sbz_cam->value());
    6. emit coordinateChanged(newCoord);
    7. }
    To copy to clipboard, switch view to plain text mode 

    works:
    1. create a new coordinate vector
    2. emit the vector

    Now, it should look like this:
    1. if sbx_cam, sby_cam, sbz_cam don't have a valid value, return
    2. otherwise create a coordinate vector
    3. and emit it

    The bad thing is I have no idea how you intend to determine that a value is not valid for you. In my opinion every real value is valid so you need a separate button outside your widget to accept the value entered in those three boxes together.
    I would also suggest that you provide a method for reading the current value of the coordinate vector instead of only emitting a signal with it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with DoubleSpinBox

    i tried the function with layout
    it's good
    Last edited by rimie23; 9th June 2012 at 16:45.

  11. #11
    Join Date
    Apr 2012
    Posts
    101
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with DoubleSpinBox

    i resolved the problem by
    1-adding the notion of flag for each spinbox
    2-i store when i execute my program the last value entred
    Last edited by rimie23; 9th June 2012 at 20:40.

Similar Threads

  1. Replies: 5
    Last Post: 25th May 2011, 10:10
  2. catch signal stepDown from doubleSpinBox
    By pospiech in forum Qt Programming
    Replies: 10
    Last Post: 3rd January 2009, 11:51

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.