I have this bit of code to draw a line on the upper border of specific row in a treeview:
class TextValidatorDelegate(QStyledItemDelegate):
"""a delegate to validate user input"""
def __init__(self, parent = None):
super().__init__(parent)
self.validator = QRegularExpressionValidator(QRegularExpression(R'[a-zA-Z0-9_]*'), self)
#issue with hdpi screen
def paint(self, painter, option, index):
super().paint(painter, option, index)
if index.data(customDataRole.WellRow):
rect = option.rect
painter.setPen(QPen())
indent = rect.left() - 50 # -50 to draw line over the expand/collapse decorations of parent items
painter.drawLine(indent, rect.top(), rect.right(), rect.top())
...
On high dpi screen when window scaling factor is set to anything other than 100%, the lines are 2px wide at start instead of 1 px. Moreover they, keep switching between 0px 1px 2px width whenever the item is hovered, or when scrolling. I have tried various options
QApplication.setAttribute(Qt.AA_DisableHighDpiScaling)
item{border : 1px solid;}
os import os.environ["QT_SCALE_FACTOR"] = "1"
And nothing changes on the high dpi monitor. The only solution I found was to disable it in windows settings. Is there an other way to draw these lines so that Windows does not try to scale them? or is there a way to stop window scaling the app (from within the app code) Thank in advance
I have this bit of code to draw a line on the upper border of specific row in a treeview:
class TextValidatorDelegate(QStyledItemDelegate):
"""a delegate to validate user input"""
def __init__(self, parent = None):
super().__init__(parent)
self.validator = QRegularExpressionValidator(QRegularExpression(R'[a-zA-Z0-9_]*'), self)
#issue with hdpi screen
def paint(self, painter, option, index):
super().paint(painter, option, index)
if index.data(customDataRole.WellRow):
rect = option.rect
painter.setPen(QPen())
indent = rect.left() - 50 # -50 to draw line over the expand/collapse decorations of parent items
painter.drawLine(indent, rect.top(), rect.right(), rect.top())
...
On high dpi screen when window scaling factor is set to anything other than 100%, the lines are 2px wide at start instead of 1 px. Moreover they, keep switching between 0px 1px 2px width whenever the item is hovered, or when scrolling. I have tried various options
QApplication.setAttribute(Qt.AA_DisableHighDpiScaling)
item{border : 1px solid;}
os import os.environ["QT_SCALE_FACTOR"] = "1"
And nothing changes on the high dpi monitor. The only solution I found was to disable it in windows settings. Is there an other way to draw these lines so that Windows does not try to scale them? or is there a way to stop window scaling the app (from within the app code) Thank in advance
from qt io forum
I found that [QT SCALE FACTOR]
is useless, as it acts a a multiplier of ms-window scale factor, so setting it to 1 has no effects. And setting it to any other value will work even on none high dpi screen, which will shrink/expand everything.
The working option is : os.environ["QT_ENABLE_HIGHDPI_SCALING"]= "0"