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. Geometry of widget
Forum Updated to NodeBB v4.3 + New Features

Geometry of widget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 1.9k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    valeria70
    wrote on last edited by
    #1

    Hi, I want to set the geometry of these widgets to define where there have to be displayed.. I would that label appear in the upper left and the buttons at bottom. I tried to test the geometry of label.. but it doesn't appear in the location I want.
    ...
    mainwin.h
    @class mainwin: public QWidget
    {
    Q_OBJECT
    private:
    QPushButton *Button1 , *Button2;
    QLabel *label;

    public:
    mainwin();
    ///.....
    }@
    mainwin.cpp
    @mainwin::mainwin()
    {
    Button1 = new QPushButton("Button1 ",this);
    Button2 = new QPushButton("Button2 ",this);
    label = new QLabel();
    label ->setStyleSheet("color: blue; background-color: red");
    label ->setGeometry(0,0,20,30); // ??

    QHBoxLayout *layout = new QHBoxLayout;

    layout->addWidget(Button1);
    layout->addWidget(Button2);
    layout->addWidget(label );
    this->setLayout(layout);
    }
    @
    main.cpp
    @int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    mainwin *mywindow=new mainwin();
    mywindow->show();
    return app.exec();
    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      If you use "layouts":http://qt-project.org/doc/qt-5/layout.html then the geometry of the widgets and their location are defined by layout management.
      You can use "spacers":http://qt-project.org/doc/qt-5/qspaceritem.html to adjust the size and location.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        setGeometry and layouts are mutually exclusive. Use setGeometry for static, non-resizable positioning and layouts for everything else.

        The layout you used is no good for this case. QHBoxLayout lays out everything from left to right.
        What you describe sounds more like a QGridLayout.
        Put label at [0,0], vertical spacer at [0,1], horizontal spacer at [0,2], and buttons at [1,2] and [2,2] grid cells.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          valeria70
          wrote on last edited by
          #4

          Ok thanks.. I tried with grid layout and it's ok.

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            Hi,

            Could you edit your first post and prepend [solved]
            That way other users can see easily it's solved. Thanks!

            Qt Certified Specialist
            www.edalsolutions.be

            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