В самом начале в книге показывают пример с возрастом и есть такие строчки:«здесь мы задаем расстояние между виджетами 6 пикселей». Но в примере ничего такого нет! Или расстояние задано неявно? Код примера :
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
window->setWindowTitle("Enter Your Age");
QSpinBox *spinBox = new QSpinBox;
QSlider *slider = new QSlider(Qt::Horizontal);
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);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(spinBox);
layout->addWidget(slider);
window->setLayout(layout);
window->show();
return app.exec();
}
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);
12 QSpinBox *spinBox = new QSpinBox(hbox);
13 QSlider *slider = new QSlider(Qt::Horizontal, hbox);
14 spinBox->setRange(0, 130);
15 slider->setRange(0, 130);
[...]
23 return app.exec();
24}
Lines 8 to 11 set up the QHBox. We call setCaption() to set the text displayed in the window’s title bar. Then we put some space (6 pixels) around and in between the child widgets. Lines 12 and 13 create a QSpinBox and a QSlider with the QHBox as the parent.
5 int main(int argc, char *argv[])
6 {
7 QApplication app(argc, argv);
8 QWidget *window = new QWidget;
9 window->setWindowTitle("Enter Your Age");
10 QSpinBox *spinBox = new QSpinBox;
11 QSlider *slider = new QSlider(Qt::Horizontal);
12 spinBox->setRange(0, 130);
13 slider->setRange(0, 130);
[...]
24 return app.exec();
25 }
Lines 8 and 9 set up the QWidget that will serve as the application's main window. We call setWindowTitle() to set the text displayed in the window's title bar. Lines 10 and 11 create a QSpinBox , and lines 12 and 13 set their valid ranges.
Форум Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)