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. QGridLayout replacing problem(in puctures)
Forum Updated to NodeBB v4.3 + New Features

QGridLayout replacing problem(in puctures)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.5k 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.
  • K Offline
    K Offline
    kirsanov
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      alexisdm
      wrote on last edited by
      #2

      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
      0
      • K Offline
        K Offline
        kirsanov
        wrote on last edited by
        #3

        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
        0
        • A Offline
          A Offline
          alexisdm
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kirsanov
            wrote on last edited by
            #5

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

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

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

                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