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. Showing grid lines in a QGridLayout
QtWS25 Last Chance

Showing grid lines in a QGridLayout

Scheduled Pinned Locked Moved General and Desktop
13 Posts 6 Posters 39.4k 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.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    Hi all,
    I was wondering if there is an easy way to show the grid lines separating sections in a grid layout governed by the QGridLayout class.
    The doc has been failing me so far but I still feel there is an easy way to achieve this.

    Thanks

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      i wouldn't count on it ... since QGridLayout is not a QWidget and thus can't draw anything ...
      The only way i see is that you insert your own "line widgets" between the widgets you enter in the grid layout. But this is alot of extra work though...

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • musimbateM Offline
        musimbateM Offline
        musimbate
        wrote on last edited by
        #3

        Thanks raven-worx,
        What do you exactly mean by ''line widget".I was thinking of subclassing QWidget ,draw the lines I want on the widget in the paint override and then apply the layout on my custom widget.Some people are even proposing to use QTableWidget and insert the widgets in the cells.I am going to try all these options but suggestions are always more than welcome.

        Thanks.

        Why join the navy if you can be a pirate?-Steve Jobs

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          [quote author="musimbate" date="1370246350"]
          What do you exactly mean by ''line widget".
          [/quote]
          you create a custom VLineWidget, HLineWidget, CrossWidget, which just paint their lines and insert them along with your other widgets to the grid layout.

          [quote author="musimbate" date="1370246350"]
          I was thinking of subclassing QWidget ,draw the lines I want on the widget in the paint override and then apply the layout on my custom widget.
          [/quote]
          i'm not sure if that will work as you want. Determining the positions for the lines could be quite difficult.

          [quote author="musimbate" date="1370246350"]
          Some people are even proposing to use QTableWidget and insert the widgets in the cells.I am going to try all these options but suggestions are always more than welcome.[/quote]
          This is by far the most easiest way to go ;)

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • musimbateM Offline
            musimbateM Offline
            musimbate
            wrote on last edited by
            #5

            [quote author="raven-worx" date="1370246783"]
            i'm not sure if that will work as you want. Determining the positions for the lines could be quite difficult.
            [/quote]
            Was starting to face that problem.Will try your "line widget idea " and QTable and see what works best.
            Thanks for your input!:-)

            Why join the navy if you can be a pirate?-Steve Jobs

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mario84
              wrote on last edited by
              #6

              [quote author="raven-worx" date="1370246783"]
              you create a custom VLineWidget, HLineWidget, CrossWidget, which just paint their lines and insert them along with your other widgets to the grid layout.
              [/quote]

              Another way could be to create a ContentWidget-Class for every cell which contains the widget that you want to show in the cell and draws a border around it...
              Perhaps this will simplify the layout ;)

              1 Reply Last reply
              0
              • B Offline
                B Offline
                belab
                wrote on last edited by
                #7

                Not sure if this would be helpful, but the designer already shows those gridlines.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Marcos Modenesi
                  wrote on last edited by
                  #8

                  May be something like !http://i.imgur.com/GoBYzTj.png(this?)!

                  @ QGridLayout *layout1 = new QGridLayout;
                  layout1->addWidget(labelMateria, 0, 0, Qt::AlignRight);
                  layout1->addWidget(lineEditMateria, 0, 1, 1, 3);
                  layout1->addWidget(labelAnyo, 1, 0, Qt::AlignRight);
                  layout1->addWidget(comboBoxAnyo, 1, 1);
                  layout1->addWidget(labelColor, 1, 3, Qt::AlignLeft);
                  layout1->addWidget(botonColor, 1, 2);
                  layout1->addWidget(labelHsCatedra, 2, 0, Qt::AlignRight);
                  layout1->addWidget(spinBoxHsCatedra, 2, 1);
                  QFrame *linea1 = new QFrame(this); // <<< this does the trick
                  linea1->setLineWidth(2);
                  linea1->setMidLineWidth(1);
                  linea1->setFrameShape(QFrame::HLine);
                  linea1->setFrameShadow(QFrame::Raised);
                  layout1->addWidget(linea1, 3, 0, 1, 4);
                  layout1->addWidget(botonCancelar, 4, 2);
                  layout1->addWidget(botonAceptar, 4, 3);

                  setLayout(layout1);@
                  
                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    flaviotordini
                    wrote on last edited by
                    #9

                    If you just need to paint a grid, subclass QWidget and draw your grid inside paintEvent.

                    1 Reply Last reply
                    0
                    • musimbateM Offline
                      musimbateM Offline
                      musimbate
                      wrote on last edited by
                      #10

                      Thanks guys for all your input.I have tried many options and I like to have many ways to achieve the same thing:-).One question about *Marcos Modenesi *'s solution though:how to control the color of the lines drawn using QFrame.I have tried to apply a palette to the frame but I am getting weird looking lines.Any ideas?
                      Thanks again!

                      Why join the navy if you can be a pirate?-Steve Jobs

                      1 Reply Last reply
                      0
                      • musimbateM Offline
                        musimbateM Offline
                        musimbate
                        wrote on last edited by
                        #11

                        [quote author="Flavio Tordini" date="1370323386"]If you just need to paint a grid, subclass QWidget and draw your grid inside paintEvent.[/quote]

                        Thanks Flavio,but I want the full functionality of a QGridLayout with grid lines shown.VLines and HLines using QFrame seem be getting me close to the desired effect.

                        Why join the navy if you can be a pirate?-Steve Jobs

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Marcos Modenesi
                          wrote on last edited by
                          #12

                          This works in my example:

                          linea1->setPalette(QPalette(QColor(255, 0, 0)));

                          @
                          QFrame *linea1 = new QFrame(this);
                          linea1->setLineWidth(2);
                          linea1->setMidLineWidth(1);
                          linea1->setFrameShape(QFrame::HLine);
                          linea1->setFrameShadow(QFrame::Raised);
                          linea1->setPalette(QPalette(QColor(255, 0, 0))); // here
                          @

                          !http://i.imgur.com/1CKZjUs.png(color red)!

                          1 Reply Last reply
                          0
                          • musimbateM Offline
                            musimbateM Offline
                            musimbate
                            wrote on last edited by
                            #13

                            Thanks Markos,I have tried that and I am still getting lines with the default color.Guess I ll have to keep looking .Thanks again.
                            Dan.

                            Why join the navy if you can be a pirate?-Steve Jobs

                            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