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
Code:
Coordinate3dWidget
::Coordinate3dWidget(QWidget *parent
):{
pos_cam
->setObjectName
(QString::fromUtf8("pos_cam"));
pos_cam
->setGeometry
(QRect(10,
50,
191,
71));
pos_cam->setTitle("Position");
sbx_cam
->setObjectName
(QString::fromUtf8("sbx_cam"));
sbx_cam
->setGeometry
(QRect(10,
40,
51,
22));
sbx_cam->setRange(-5000, 5000);
lx_cam
->setObjectName
(QString::fromUtf8("lx_cam"));
lx_cam
->setGeometry
(QRect(10,
20,
46,
13));
sby_cam
->setObjectName
(QString::fromUtf8("sby_cam"));
sby_cam
->setGeometry
(QRect(70,
40,
51,
22));
sby_cam->setRange(-5000, 5000);
ly_cam
->setObjectName
(QString::fromUtf8("ly_cam"));
ly_cam
->setGeometry
(QRect(70,
20,
46,
13));
sbz_cam
->setObjectName
(QString::fromUtf8("sbz_cam"));
sbz_cam
->setGeometry
(QRect(130,
40,
51,
22));
sbz_cam->setRange(-5000, 5000);
lz_cam
->setObjectName
(QString::fromUtf8("lz_cam"));
lz_cam
->setGeometry
(QRect(130,
20,
46,
13));
connect(sbx_cam, SIGNAL(editingFinished()), this, SLOT(onCoordinateChanged()));
connect(sby_cam, SIGNAL(editingFinished()), this, SLOT(onCoordinateChanged()));
connect(sbz_cam, SIGNAL(editingFinished()), this, SLOT(onCoordinateChanged()));
}
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
Re: problem with DoubleSpinBox
Do yourself a favour and read about using layouts.
Re: problem with DoubleSpinBox
Re: problem with DoubleSpinBox
Hi
i do not use layout her
i just use groupbox
Re: problem with DoubleSpinBox
Quote:
Originally Posted by
dreamvig
i do not use layout her
Yes, I can see that.
Quote:
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:
Code:
int main(int argc, char **argv) {
Coordinate3dWidget w;
f.setPointSize(72);
w.setFont(f);
w.show();
Coordinate3dWidget w2;
f.setPointSize(4);
w2.setFont(f);
w2.show();
return app.exec();
}
How does it look? I hope this answers rimie23's question as well. Conclusions are yours to draw.
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
Code:
ogreWidget = new OgreWidget(this);
setCentralWidget(ogreWidget);
page_14 = new Coordinate3dWidget;
onnect(page_14, SIGNAL(coordinateChanged(const Ogre::Vector3&)),
ogreWidget, SLOT(setCameraPosition(const Ogre::Vector3&)));
connect(ogreWidget, SIGNAL(cameraPositionChanged(const Ogre::Vector3&)),
page_14, SLOT(setNewCoordinate(const Ogre::Vector3&)));
that mean i related it where i draw the object
it just do net let me finishe entring in the three spinbox
Re: problem with DoubleSpinBox
Quote:
Originally Posted by
dreamvig
i don't undertand what you want by this exemple
Maybe if you ran it, you'd understand.
Quote:
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.
Re: problem with DoubleSpinBox
I am so sorry
i know that my english is bad (it's not my native language )
Quote:
. 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
Code:
class Coordinate3dWidget
: public QWidget{
Q_OBJECT
public:
Coordinate3dWidget
(QWidget *parent
=0);
public slots:
void setNewCoordinate(const Ogre::Vector3 &coordinate);
signals:
void coordinateChanged(const Ogre::Vector3 &coordinate);
private slots:
void onCoordinateChanged();
private:
};
in Coordinate3dWidget.cpp
Code:
#include <QLabel>
#include <QHBoxLayout>
#include <QToolButton>
#include <QPushButton>
#include "coordinate3dwidget.h"
#include"my_interface.h"
//class MainWindow;
Coordinate3dWidget
::Coordinate3dWidget(QWidget *parent
):{
pos_cam
->setObjectName
(QString::fromUtf8("pos_cam"));
pos_cam
->setGeometry
(QRect(10,
50,
191,
71));
pos_cam->setTitle("Position");
sbx_cam
->setObjectName
(QString::fromUtf8("sbx_cam"));
sbx_cam
->setGeometry
(QRect(10,
40,
51,
22));
sbx_cam->setRange(-5000, 5000);
lx_cam
->setObjectName
(QString::fromUtf8("lx_cam"));
lx_cam
->setGeometry
(QRect(10,
20,
46,
13));
sby_cam
->setObjectName
(QString::fromUtf8("sby_cam"));
sby_cam
->setGeometry
(QRect(70,
40,
51,
22));
sby_cam->setRange(-5000, 5000);
ly_cam
->setObjectName
(QString::fromUtf8("ly_cam"));
ly_cam
->setGeometry
(QRect(70,
20,
46,
13));
sbz_cam
->setObjectName
(QString::fromUtf8("sbz_cam"));
sbz_cam
->setGeometry
(QRect(130,
40,
51,
22));
sbz_cam->setRange(-5000, 5000);
lz_cam
->setObjectName
(QString::fromUtf8("lz_cam"));
lz_cam
->setGeometry
(QRect(130,
20,
46,
13));
connect(sbx_cam, SIGNAL(/*valueChanged*/editingFinished()), this, SLOT(onCoordinateChanged()));
connect(sby_cam, SIGNAL(/*valueChanged*/editingFinished()), this, SLOT(onCoordinateChanged()));
connect(sbz_cam, SIGNAL(/*valueChanged*/editingFinished()), this, SLOT(onCoordinateChanged()));
}
void Coordinate3dWidget::setNewCoordinate(const Ogre::Vector3 &coordinate)
{
blockSignals(true);
sbx_cam->setValue(coordinate.x);
sby_cam->setValue(coordinate.y);
sbz_cam->setValue(coordinate.z);
blockSignals(false);
}
void Coordinate3dWidget::onCoordinateChanged()
{
Ogre::Vector3 newCoord(sbx_cam->value(),
sby_cam->value(),
sbz_cam->value());
emit coordinateChanged(newCoord);
}
and in my mainwindow
Code:
MainWindow::MainWindow()
{
ogreWidget = new OgreWidget(this);
setCentralWidget(ogreWidget);
createDockWidget();
}
void MainWindow::createDockWidget()
{
page_14 = new Coordinate3dWidget;
page_14
->setGeometry
(QRect(0,
0,
211,
250));
connect(page_14, SIGNAL(coordinateChanged(const Ogre::Vector3&)),
ogreWidget, SLOT(setCameraPosition(const Ogre::Vector3&)));
connect(ogreWidget, SIGNAL(cameraPositionChanged(const Ogre::Vector3&)),
page_14, SLOT(setNewCoordinate(const Ogre::Vector3&)));
in my class OgreWidget i defined slot
Code:
public slots:
void setCameraPosition(const Ogre::Vector3 &pos);
Code:
in setCameraPosition: when i entre the numbers in the three boxes i must execute this slot to add object in the position entred
void QOgreWidget::setCameraPosition(const Ogre::Vector3 &pos)
{
CamNode= mSceneMgr->getRootSceneNode()->createChildSceneNode();
ent_cam = mSceneMgr->createEntity( Ogre::SceneManager:: PT_CUBE);
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("green", "General");
material->getTechnique( 0 )->getPass( 0 )->setAmbient(1, 1, 0);
ent_cam->setMaterial(material);
mSceneMgr->getRootSceneNode()->createChildSceneNode();
CamNode->setPosition(pos);
CamNode->attachObject(ent_cam);
}
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.
Code:
Coordinate3dWidget
::Coordinate3dWidget(QWidget *parent
):{
setTitle("Position");
sbx_cam->setRange(-5000, 5000);
lx_cam->setText(tr("X"));
l->addWidget(lx_cam, 0,0);
l->addWidget(sbx_cam, 1, 0);
sby_cam->setRange(-5000, 5000);
ly_cam->setText(tr("Y"));
l->addWidget(ly_cam, 0,1);
l->addWidget(sby_cam, 1, 1);
sbz_cam->setRange(-5000, 5000);
lz_cam->setText(tr("Z"));
l->addWidget(lx_cam, 0,2);
l->addWidget(sbz_cam, 1, 2);
connect(sbx_cam, SIGNAL(valueChanged(double)), this, SLOT(onCoordinateChanged()));
connect(sby_cam, SIGNAL(valueChanged(double)), this, SLOT(onCoordinateChanged()));
connect(sbz_cam, SIGNAL(valueChanged(double)), this, SLOT(onCoordinateChanged()));
}
Isn't that clearer and doesn't it work better?
Now for your main problem... here is how your "onCoordinateChanged()" which looks like:
Code:
void Coordinate3dWidget::onCoordinateChanged()
{
Ogre::Vector3 newCoord(sbx_cam->value(),
sby_cam->value(),
sbz_cam->value());
emit coordinateChanged(newCoord);
}
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.
Re: problem with DoubleSpinBox
i tried the function with layout
it's good
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