Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] hbox
QtWS25 Last Chance

[solved] hbox

Scheduled Pinned Locked Moved General and Desktop
12 Posts 5 Posters 4.7k Views
  • 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.
  • S Offline
    S Offline
    Sam
    wrote on last edited by
    #3

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

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #4

      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
      0
      • T Offline
        T Offline
        tecky
        wrote on last edited by
        #5

        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
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #6

          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
          0
          • T Offline
            T Offline
            tecky
            wrote on last edited by
            #7

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8
              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
              0
              • T Offline
                T Offline
                tecky
                wrote on last edited by
                #9

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

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  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
                  0
                  • T Offline
                    T Offline
                    tecky
                    wrote on last edited by
                    #11

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

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved