[solved] hbox
-
1 #include <qapplication.h>
2 #include <qwidget.h>
3 #include <qslider.h>
4 #include <qspinbox.h>
5 int main(int argc, char *argv[])
6 {
7 QApplication app(argc, argv);
8 QHBox *hbox = new QHBox(0);
9 hbox->setCaption("Enter Your Age");
10 hbox->setMargin(6);
11 hbox->setSpacing(6);
....
....
why 9-10 lines dont set my values
"D:\qt\projS\project2\main.cpp:9: error: 'setCaption' was not declared in this scope"??
how write it correct?
Qt 5.0.2 -
In Qt4 and 5 the QHBox should be used any more. Read the porting site:
"Porting to Qt4":http://qt-project.org/doc/qt-4.8/porting4.html
As mentioned use a QHorizontalLayout and add a QLabel to it.
Greetz -
If you want a Caption over a Layout you can use a QGroupBox with a QHBoxLayout inside
@
QGroupBox *box = new QGroupBox (0);
box->setTitle (tr("Enter your Age"));QHBoxLayout *l = new QHBoxLayout;
l->setSpacing (6);
l->setContentsMargins (6, 6, 6, 6);
// Add Widgets to Layoutbox->setLayout(l);
@ -
now it works, but ...cant understand
-
what is "tr" in 2nd line? ( i deleted it)
error :D:\qt\projS\project2\main.cpp:12: ошибка: 'tr' was not declared in this scope -
@#include <qapplication.h>
#include <qslider.h>
#include <qwidget.h>
#include <qspinbox.h>
#include <QHBoxLayout>
#include <QGroupbox.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QGroupBox *hbox = new QGroupBox (0);
hbox->setTitle (("Enter your Age"));
QHBoxLayout *l = new QHBoxLayout;
l->setSpacing (6);
l->setContentsMargins (6, 6, 6, 6);
hbox->setLayout(l);
QSpinBox *spinBox = new QSpinBox(hbox);
QSlider *slider = new QSlider(Qt::Horizontal, hbox);
spinBox->setRange(0, 130);
slider->setRange(0, 130);
QObject::connect(spinBox, SIGNAL(valueChanged(int)),
slider, SLOT(setValue(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)),
spinBox, SLOT(setValue(int)));
spinBox->setValue(35);
hbox->show();
return app.exec();
}
@
name of hbox is still "project2"
and margins are not taken into account...cant get it
-
-
-
tr is a static QObject function for translation, since your in main you have to use it like that:
@hbox->setTitle(QObject::tr("Enter your age"));@ -
You are not putting your widgets in your layout.
@l.addWidget(spinBox);
l.addWidget(slider);@
-
-
You're welcome
Since it's solved, don't forget to update the thread's title :)
-
Simply prepend [solved] to your thread's title