Recent Posts

How to fit the widget to the parent layout in PySide2

GOAL

To fit the sizes of the children widgets to the layout of the parent. In other words, to remove the space around widgets from the layout.

Environment

Windows 10
Python 3.8.7
PySide2 5.15.2

Method

There are 2 steps to delete margin space from the layout.

  1. Set the margin of the layout 0
  2. Set the spacing of the layout 0
(more…)

How to fit the selected color to the cell in QTreeWidget

The length of selected color depends on the length of the string in QTreeWidget of PySide2. How can I fit the length of the cell?

GOAL

To fill the color to fit the size of the cell when the item is selected. (See the article “How to select one column of QTreeWidgetItem in PySide2” to generate an tree widget that allows users to select each item.)

Environment

Windows 10
Python 3.8.7
PySide2 5.15.2

Method

Set show-decoration-selected of qss(QStyleSheet) that can be used for QTreeWidget, QTreeView, QListWidget and QListView.

Controls whether selections in a QListView cover the entire row or just the extent of the text.

from Qt Style Sheets Reference

Use setStyleSheet to set qss to the widget as below.

self.tree_widget.setStyleSheet('QTreeView { show-decoration-selected: 1;}')

See the official documentation “Qt Style Sheets” for details about qss.

Categories

AfterEffects Algorithm Artificial Intelligence Blender C++ Computer Graphics Computer Science Daily Life DataAnalytics Event Game ImageProcessing JavaScript Kotlin mathematics Maya PHP Python SoftwareEngineering Tips Today's paper Tools TroubleShooting Unity Visual Sudio Web Windows WordPress 未分類