Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Trouble with QGridLayout row spacing
Forum Updated to NodeBB v4.3 + New Features

Trouble with QGridLayout row spacing

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 1 Posters 566 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.
  • S Offline
    S Offline
    SassyDino
    wrote on last edited by
    #1

    Hey all! So I'm currently working on a random little personal project using PyQt6 (which I'm pretty new to as a library) and have run into a problem with QGridLayout, wherein the rows seem to be randomly changing their height halfway down the grid without any apparent cause. I'm first creating an object for the QGridLayout, then using a for loop to iteratively create rows based on a list I have provided. See below the issue I'm having:

    pyqt6_forum1.png

    I'm noticing two points where the rows are behaving strangely: the first row (auto) is slightly compressed compared to the other rows, and then after the "sgl" row the rows just seem to change height for no apparent reason. This is the code I'm using to fill the empty QGridLayout (self.deep_page):

    self.weap_head = QLabel("Weapon")
    self.deep_page.addWidget(self.weap_head, 0, 0)
    
    ex = 1                  # Used to account for gridlines when plotting to grid coords
    for n, types in enumerate(weap_types):
            print(f"Weapon: {types}: rdiv{n}")           # debug
    
            # Inserts gridline above next cell
            self.divs[f"rdiv{types}"] = QFrame()
            self.divs[f"rdiv{types}"].setFrameStyle(4)
            self.deep_page.addWidget(self.divs[f"rdiv{types}"], n+ex, 0, 1, -1)
    
            # Inserts next cell
            self.types[types] = QLabel(types)
            self.deep_page.addWidget(self.types[types], n+ex+1, 0, alignment=Qt.AlignmentFlag.AlignCenter)
            self.deep_page.setRowMinimumHeight(n+2, 15)
    
            ex += 1
                
    self.vend = QLabel("test")
    self.deep_page.addWidget(self.vend, (len(weap_types)*2)+2, 0, 1, -1)
    self.deep_page.setRowStretch((len(weap_types)*2)+2, 100)
    

    (self.divs is just a dictionary I'm using to store the QFrame() grid dividers for later reference, and the same with self.types which I'm using to store the QLabel() text to modify later on)
    Also, weap_types is just a simple list, just for clarity:

    weap_types = ["auto", "bow", "hc", "pulse", "scout", "sidearm", "smg", "fusion", "glaive",
                  "sgl", "shotgun", "sniper", "trace", "hgl", "linear", "mg", "rocket", "sword", "extra1", "extra2", "extra3"]
    

    As you can see, I'm doing nothing (intentionally) to modify the row heights differently for each iteration or anything. I've played around with trying to set stretch factors and different alignment flags for all of the objects, but the result is pretty much the same. Changing the minimum row height (currently set to 15) does change the row widths, but the same issue is still apparent wherein the same rows are all squashed (or maybe the top half is stretched?).

    I added those 3 lines of code at the end to add a single row with stretch enabled hoping that would help, but it made no difference (although to be fair it shouldn't have made a difference anyway as the whole widget is part of a QScrollBar so I can scroll through it, so the rows don't stretch when I resize the window anyway).

    I'm just at a loss as to why the rows are behaving like this, I've tried everything I can think of, including just entirely re-writing the code from scratch after previous trial-and-error failed. Any help would be appreciated, I feel like I'm just missing something super obvious but I'm at wits end!!!

    1 Reply Last reply
    0
    • S SassyDino has marked this topic as solved on
    • S Offline
      S Offline
      SassyDino
      wrote on last edited by
      #2

      Fixed. I was being a bit silly, and not sure how I missed this for so long: I needed to set the minimum row height to 15 for the row "n+ex+2", rather than "n+2" as I was doing.

      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