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] Adding to a QGridLayout the way Creator can.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Adding to a QGridLayout the way Creator can.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.7k Views 2 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #1

    Hi
    In Creator you can add widgets to a QGridLayout
    and it can add / remove Columns doing so.

    So If have w1 w2 w3
    I can drag between a widget w2 and w3 to get
    w1 w2 MyNew w3

    How can I do this from code / dynamic ? (seems not to be possible)
    The

    void QGridLayout::addWidget(QWidget * widget, int row, int column, Qt::Alignment alignment = 0)
    

    Will replace what ever widget already in row, column, not make room for new one.

    Thank you

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

      Hi,

      Just put the widget on the row/column you want:

      QGridLayout *layout = new QGridLayout;
      layout->addWidget(new QPushButton(tr("Test1")), 0, 0);
      layout->addWidget(new QPushButton(tr("Test2")), 1, 1);
      layout->addWidget(new QPushButton(tr("Test3")), 2, 2);
      

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

      mrjjM 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Just put the widget on the row/column you want:

        QGridLayout *layout = new QGridLayout;
        layout->addWidget(new QPushButton(tr("Test1")), 0, 0);
        layout->addWidget(new QPushButton(tr("Test2")), 1, 1);
        layout->addWidget(new QPushButton(tr("Test3")), 2, 2);
        
        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        @SGaist
        well I want to (later) insert a new one between Test1 and Test2. (imagine they are on same row)
        Like I can in Creator.
        Is that possible ?

        It seems to replace any widget there.not add an extra.

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

          Indeed, it seems that a replace + add combo is the only way

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

          mrjjM 1 Reply Last reply
          0
          • SGaistS SGaist

            Indeed, it seems that a replace + add combo is the only way

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @SGaist
            Hi, ok, i kinda fear that it would not work that way.
            Im going to try to use a widget with a layout to fake a row instead.

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

              QHorizontalLayout + QVerticalLayout ?

              You can also check the sources of designer to see how it's done there

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

              mrjjM 1 Reply Last reply
              0
              • SGaistS SGaist

                QHorizontalLayout + QVerticalLayout ?

                You can also check the sources of designer to see how it's done there

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @SGaist
                I actually tried to use the source (luke) but I could simply not spot the files where such
                drag and drop would happen. Grep didn't help me this time :(

                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