Python Forum
[PyQt] QTreeView, StyleSheet resizes last column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] QTreeView, StyleSheet resizes last column
#1
I am using a QTreeView with a StyleSheet set to it. This tree has checkboxes, and the style replaces the image for the empty, checked and partially checked boxes. My issue is, when I set the StyleSheet, the last column/section is stretched beyond what I set it to (I manually set section/column sizes via tree.setColumnWidth(). I've also tried header.resizeSection()). Without the StyleSheet, everything works as intended.

I'm not going to share code (I know that will limit any help) because 1) it's split up over multiple modules, and 2) I believe it to be buggy type behavior within StyleSheets (I read StyleSheets are kinda buggy). If it is buggy behavior, is there a workaround?

Currently, I have my app working the way I want by setting the layout's size (QGridLayout: column width) that houses the QTreeView. This question is more for academic purposes—can it be fixed via StyleSheets or something else?

I've tried QTreeView::section:last{width: 110;}, QTreeView::section:last{max-width: 110;}, and header.setMaximumSectionSize(110). Any ideas?
Reply
#2
Without code it will be hard for anyone to help. You could try setColumnStretch()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
(Sep-15-2023, 12:48 PM)menator01 Wrote: Without code it will be hard for anyone to help. You could try setColumnStretch()

I know for people to best help me I need to share code. But, I just don't feel like digging through and extracting the relevant sections to provide a MRE, especially when my app does what I want now. Like I said, this question is purely academic. I was hoping to solve it via StyleSheets, and in the process learn more about them. I thought it through prior to posting, and one really doesn't need code to fix the issue if it can be done via StyleSheets. StyleSheet syntax is straight forward. I shared what I've tried with them.

So, that's that.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Changing a column header in QTreeView DrakeSoft 4 3,626 Jun-25-2022, 09:11 AM
Last Post: DrakeSoft
  [PyQt] QTableWidget stylesheet error mart79 3 6,464 Feb-26-2020, 04:54 PM
Last Post: Denni
  [PyQt] How to reference QTreeView QHeaderView setResizeMode Denni 1 3,750 Jun-11-2019, 10:20 PM
Last Post: Alfalfa
  Cannot Import stylesheet BG? mekha 1 2,269 Aug-08-2018, 04:49 AM
Last Post: mekha
  [PyQt] QTreeView branches and their clickable area not coinciding abstracted 0 3,726 Mar-17-2017, 02:28 AM
Last Post: abstracted

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020