Qt Forum

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

    Forum Updated on Feb 6th

    QGridLayout replacing problem(in puctures)

    General and Desktop
    2
    7
    3217
    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.
    • K
      kirsanov last edited by

      I have problem of placing widgets in QGridLayout. I replace ships onMouseWeeling(I want to make them horizontal o vertical). But first type they place correctly, after it they place bad.
      First placing:
      !http://habrastorage.org/storage2/7f2/c9a/01e/7f2c9a01e6619ae7acae4075e93ce745.png(lalala)!
      second placing:
      !http://habrastorage.org/storage2/125/a6a/b54/125a6ab5411ee0c62ae307fbc1ec3400.png(lalala2)!
      but must be:
      !http://habrastorage.org/storage2/df8/d6f/4d9/df8d6f4d93c41b34665b8d7951ba731b.png(lalala3)!

      How can I solve this problem?
      Thks in advance.

      1 Reply Last reply Reply Quote 0
      • A
        alexisdm last edited by

        From the picture it seems you correctly swapped the row span and column span, but the row and column parameters are the same as the horizontal placing when they should also be swapped.

        1 Reply Last reply Reply Quote 0
        • K
          kirsanov last edited by

          I don't think so, I think that problem is in updating.
          Here is a code of replacing:
          @void MainWindow::setUpShips() {
          if (shipsLayout) {
          delete shipsLayout;
          }
          shipsLayout = new QGridLayout;
          if (Ship::orientation == Ship::HORIZONTAL) {
          shipsLayout->addWidget(ships[3], 0, 0, 1, 2);
          shipsLayout->addWidget(ships[2], 1, 0, 1, 2);
          shipsLayout->addWidget(ships[1], 2, 0);
          shipsLayout->addWidget(ships[0], 2, 1);
          } else {
          shipsLayout->addWidget(ships[3], 0, 0, 2, 1);
          shipsLayout->addWidget(ships[2], 0, 1, 2, 1);
          shipsLayout->addWidget(ships[1], 0, 2);
          shipsLayout->addWidget(ships[0], 1, 2);
          }
          }@

          1 Reply Last reply Reply Quote 0
          • A
            alexisdm last edited by

            Do you call addLayout or setLayout after that, to reapply the layout ?

            1 Reply Last reply Reply Quote 0
            • K
              kirsanov last edited by

              I don't reapply the layout.
              I place all components one time in the constructor of MainWindow.
              @startButton = new QPushButton(tr("Start"));
              startButton->setEnabled(false);
              restartButton = new QPushButton(tr("Restart"));
              restartButton->setVisible(false);
              rSea->setVisible(false);
              rSea->fillRandom();

              shipsLayout = 0;
              setUpShips();
              
              playerScoreLable = new QLabel("Your score");
              compScoreLable = new QLabel("Computer score");
              playerScoreEdit = new QLineEdit("0");
              compScoreEdit = new QLineEdit("0");
              playerScoreEdit->setEnabled(false);
              compScoreEdit->setEnabled(false);
              

              ...@

              1 Reply Last reply Reply Quote 0
              • A
                alexisdm last edited by

                If you delete the layout in setUpShips, you should somehow "reattach" the new layout to the MainWindow.
                So where is the line that either set shipsLayout as a widget layout, or that adds shipsLayout to another layout ?

                But you could probably reuse the same layout with
                @if (!shipsLayout) {
                shipsLayout = new QGridLayout;
                }
                @

                instead of

                @if (shipsLayout) {
                delete shipsLayout;
                }
                shipsLayout = new QGridLayout;@

                Widgets that are already present in the layout will simply move to their new position.

                1 Reply Last reply Reply Quote 0
                • K
                  kirsanov last edited by

                  Thank you very much). Your advice has solved my problem perfectly.

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