Qt World Summit: Submit your Presentation

[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

  • Simply,

    QHBoxLayout doesn't have setCaption() and setMargin() methods

  • You need to create a QLabel and then add it to your QHboxLayout layout.

  • 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.

  • ty guys, i understood it (my exemple Qt3 and i use Qt5)
    but i still newbie((
    can u help me set this 3 values step by step
    (just correct my lines)
    I will be grateful

  • 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 Layout


  • now it works, but ...cant understand

    1. what is "tr" in 2nd line? ( i deleted it)
      error :D:\qt\projS\project2\main.cpp:12: ошибка: 'tr' was not declared in this scope

    2. @#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);
    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)));
    return app.exec();
    name of hbox is still "project2"
    and margins are not taken into account

    ...cant get it

  • Lifetime Qt Champion

    1. 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"));@

    2. You are not putting your widgets in your layout.

  • ty. now its ok
    , not "."

  • Lifetime Qt Champion

    You're welcome

    Since it's solved, don't forget to update the thread's title :)

  • is it something like a "done"?
    (grey color)

  • Lifetime Qt Champion

    Simply prepend [solved] to your thread's title

Log in to reply