Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved] hbox

    General and Desktop
    5
    12
    4125
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tecky last edited by

      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

      1 Reply Last reply Reply Quote 0
      • M
        mcosta last edited by

        Simply,

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

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        1 Reply Last reply Reply Quote 0
        • S
          Sam last edited by

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

          1 Reply Last reply Reply Quote 0
          • Jeroentjehome
            Jeroentjehome last edited by

            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

            Greetz, Jeroen

            1 Reply Last reply Reply Quote 0
            • T
              tecky last edited by

              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

              1 Reply Last reply Reply Quote 0
              • M
                mcosta last edited by

                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

                box->setLayout(l);
                @

                Once your problem is solved don't forget to:

                • Mark the thread as SOLVED using the Topic Tool menu
                • Vote up the answer(s) that helped you to solve the issue

                You can embed images using (http://imgur.com/) or (http://postimage.org/)

                1 Reply Last reply Reply Quote 0
                • T
                  tecky last edited by

                  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);
                  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

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    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.
                      @l.addWidget(spinBox);
                      l.addWidget(slider);@

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply Reply Quote 0
                    • T
                      tecky last edited by

                      ty. now its ok
                      (btw
                      @
                      l->addWidget(spinBox);
                      l->addWidget(slider);
                      @
                      , not "."

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        You're welcome

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

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply Reply Quote 0
                        • T
                          tecky last edited by

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

                          1 Reply Last reply Reply Quote 0
                          • SGaist
                            SGaist Lifetime Qt Champion last edited by

                            Simply prepend [solved] to your thread's title

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post