Difficulty displaying frame around QTreeView
Maurizio Berti
maurizio.berti at gmail.com
Sat Sep 20 03:32:25 BST 2025
First of all, please be aware that this is almost certainly *not* a PyQt
issue.
After that, if you're not certain if the display scaling may be related,
the simplest solution is to simply change your display settings and see
what happens.
Then, some Qt widget types may behave differently depending on their
relationship within the window management environment: the same QWidget can
have different appearance and metrics (including margins, borders, etc.)
depending on many aspects: QWidget subclasses (standard Qt types or custom
subclasses) may work differently if they're top level windows or not, which
also is quite relevant for dialogs (which can be treated differently
depending on the OS, including different versions of the same platform).
Some further suggestions:
- make a practical, immediate comparison; don't ask people to manually test
differences (which may be difficult to compare across modifications) or
modify your code in ways that would potentially invalidate your case:
create a program that shows *two* windows with the different
container_frame value (possibly with a related window title to simplify
recognition) so that everybody can easily see the differences at a glance;
- check if adding contents to a different *and/or* further container makes
any difference (eg: use QWidget instead of QDialog, then also try to add
the different "windows" to a main top level window); it's quite normal for
a container widget to display itself differently depending on the window
management relation: a "frame" may need a visual hint when added to a
further layout for which it may be part of a more relevant "widget
hierarchy", while that hint may not be that relevant if it's a top level
window itself;
- remember that Qt scroll areas all inherit from QAbstractScrollArea, which
in turn inherits from QFrame, making the above statement even more
relevant; some styles draw contents quite differently depending on their
"level" within the top level window (the base QWidget itself behaves
differently in some situations, depending on its top level state);
- Qt widget styling is quite complex and not always perfect; I've seen some
cases of widgets behaving/displaying differently depending on when/how
they're created or added to a parent, because some widgets (especially
complex ones such as scroll areas) are in part definitively "initialized"
at some point and not properly updated afterwards, even if the parent (or
the style) has changed;
- also remember that, while the "fusion" style is intended to be as
consistent as possible across different systems, every platform, OS
version, system (hw+sw) and user configuration has its own quirks;
specifically, some "metrics" and related appearances (frames, boxes,
paddings, margins and related appearances, even including border sizes and
their display) will always potentially be shown somehow differently, even
on theoretically "similar" systems;
- finally, while relatively rare, even the above compliant "fusion" style
has received some updates, even indirectly (possibly causing some
regressions due to the introduction of changes that may affect it; consider
the case of the "modern" window style introduced in Qt 6.7);
Best regards,
MaurizioB
Il giorno sab 20 set 2025 alle ore 03:15 John Sturtz <john at sturtz.org> ha
scritto:
> Hello again good PyQt folks.
>
> I'm having a deal of trouble consistently displaying the frame that (I
> think) should appear around a QTreeView, which is embedded in a QDialog.
> I specify the frame as follows:
>
> self.treeView.setFrameStyle(
> QtWidgets.QFrame.Shape.StyledPanel|
> QtWidgets.QFrame.Shadow.Raised
> )
>
> Sometimes the frame doesn't display at all. Sometimes parts of it will
> display (for example, three sides but not the fourth).
>
> Attached is a sample script. It does two different things (controlled by
> setting the boolean variable on line #14).
>
> (1)
> In one case, it creates a QTreeView, places it inside a QHBoxLayout, and
> puts the layout into the main layout for the QDialog. On my computer,
> what I get in this case is frame on both sides and the bottom of the tree
> view, but not the top.
>
> (2)
> In the other case, the script creates the QTreeView, puts the tree view
> into a QHBoxLayout, then puts that layout into a QFrame and adds the
> frame to the dialog's main layout. In that case, I get no frame around the
> tree view at all.
>
> (Toggle between case 1 and case 2 by setting the boolean on line #14 to
> False or True, respectively).
>
> Am I doing something wrong here?
>
> BTW, this is Windows 11, and I have the System>Display Scale setting to
> 125%. It this possibly the cause of the problem?
>
> Thanks again!
>
> /John
>
--
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20250920/88bd2a84/attachment-0001.htm>
More information about the PyQt
mailing list