Resize model columns properly by hand
This commit is contained in:
parent
35006bd246
commit
5933585a23
1
THANKS
1
THANKS
@ -26,6 +26,7 @@ valuable ones:
|
|||||||
- quark
|
- quark
|
||||||
- Bleeding Fingers
|
- Bleeding Fingers
|
||||||
- artyom.stv
|
- artyom.stv
|
||||||
|
- hank
|
||||||
|
|
||||||
Thanks to these people for helpful bits and pieces in the Qt bugtracker and IRC
|
Thanks to these people for helpful bits and pieces in the Qt bugtracker and IRC
|
||||||
channels:
|
channels:
|
||||||
|
@ -55,6 +55,7 @@ class CompletionView(QTreeView):
|
|||||||
|
|
||||||
Class attributes:
|
Class attributes:
|
||||||
STYLESHEET: The stylesheet template for the CompletionView.
|
STYLESHEET: The stylesheet template for the CompletionView.
|
||||||
|
COLUMN_WIDTHS: A list of column widths, in percent.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_model: The currently active filter model.
|
_model: The currently active filter model.
|
||||||
@ -100,6 +101,7 @@ class CompletionView(QTreeView):
|
|||||||
{color[completion.item.selected.fg]}
|
{color[completion.item.selected.fg]}
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
|
COLUMN_WIDTHS = [20, 70, 10]
|
||||||
|
|
||||||
change_completed_part = pyqtSignal(str)
|
change_completed_part = pyqtSignal(str)
|
||||||
|
|
||||||
@ -143,8 +145,9 @@ class CompletionView(QTreeView):
|
|||||||
self._models['option'] = {}
|
self._models['option'] = {}
|
||||||
self._models['value'] = {}
|
self._models['value'] = {}
|
||||||
for sectname, sect in configdata.DATA.items():
|
for sectname, sect in configdata.DATA.items():
|
||||||
self._models['option'][sectname] = CFM(
|
optmodel = CFM(SettingOptionCompletionModel(sectname, self))
|
||||||
SettingOptionCompletionModel(sectname, self))
|
self._models['option'][sectname] = optmodel
|
||||||
|
config.instance.changed.connect(optmodel.srcmodel.on_config_changed)
|
||||||
if hasattr(sect, 'valtype'):
|
if hasattr(sect, 'valtype'):
|
||||||
# Same type for all values (ValueList)
|
# Same type for all values (ValueList)
|
||||||
try:
|
try:
|
||||||
@ -162,6 +165,16 @@ class CompletionView(QTreeView):
|
|||||||
except NoCompletionsError:
|
except NoCompletionsError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _resize_columns(self):
|
||||||
|
"""Resize the completion columns based on COLUMN_WIDTHS."""
|
||||||
|
width = self.size().width()
|
||||||
|
pixel_widths = [(width * perc // 100) for perc in self.COLUMN_WIDTHS]
|
||||||
|
if self.verticalScrollBar().isVisible():
|
||||||
|
pixel_widths[-1] -= self.style().pixelMetric(
|
||||||
|
QStyle.PM_ScrollBarExtent) + 5
|
||||||
|
for i, w in enumerate(pixel_widths):
|
||||||
|
self.setColumnWidth(i, w)
|
||||||
|
|
||||||
def _next_idx(self, upwards):
|
def _next_idx(self, upwards):
|
||||||
"""Get the previous/next QModelIndex displayed in the view.
|
"""Get the previous/next QModelIndex displayed in the view.
|
||||||
|
|
||||||
@ -262,7 +275,7 @@ class CompletionView(QTreeView):
|
|||||||
self.setModel(model)
|
self.setModel(model)
|
||||||
self._model = model
|
self._model = model
|
||||||
self.expandAll()
|
self.expandAll()
|
||||||
self.resizeColumnToContents(0)
|
self._resize_columns()
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def on_config_changed(self, section, option):
|
def on_config_changed(self, section, option):
|
||||||
@ -356,6 +369,11 @@ class CompletionView(QTreeView):
|
|||||||
self.change_completed_part.emit(data)
|
self.change_completed_part.emit(data)
|
||||||
super().selectionChanged(selected, deselected)
|
super().selectionChanged(selected, deselected)
|
||||||
|
|
||||||
|
def resizeEvent(self, e):
|
||||||
|
"""Extend resizeEvent to adjust column size."""
|
||||||
|
super().resizeEvent(e)
|
||||||
|
self._resize_columns()
|
||||||
|
|
||||||
|
|
||||||
class _CompletionItemDelegate(QStyledItemDelegate):
|
class _CompletionItemDelegate(QStyledItemDelegate):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user