Results 1 to 11 of 11

Thread: problem with DoubleSpinBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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.


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