Dynamically re-size the search results view

windows_fixes_yo
Tyler Goodlet 2022-02-10 14:22:46 -05:00
parent 51d94a301a
commit 890ffc76cf
1 changed files with 28 additions and 15 deletions

View File

@ -39,6 +39,7 @@ from typing import (
Awaitable, Sequence, Awaitable, Sequence,
Any, AsyncIterator Any, AsyncIterator
) )
from math import ceil
import time import time
# from pprint import pformat # from pprint import pformat
@ -49,7 +50,6 @@ from PyQt5 import QtCore
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
from PyQt5.QtCore import ( from PyQt5.QtCore import (
Qt, Qt,
QSize,
QModelIndex, QModelIndex,
QItemSelectionModel, QItemSelectionModel,
) )
@ -158,16 +158,25 @@ class CompleterView(QTreeView):
self.setStyleSheet(f"font: {size}px") self.setStyleSheet(f"font: {size}px")
#def resizeEvent(self, event: 'QEvent') -> None: # def resizeEvent(self, event: 'QEvent') -> None:
# self.resize_to_results() # self.resize_to_results()
# super().resizeEvent(event) # super().resizeEvent(event)
def on_resize(self) -> None:
'''
Resize relay event from god.
'''
self.resize_to_results()
def resize_to_results(self): def resize_to_results(self):
model = self.model() model = self.model()
cols = model.columnCount() cols = model.columnCount()
col_w_tot = 0
for i in range(cols): for i in range(cols):
self.resizeColumnToContents(i) self.resizeColumnToContents(i)
col_w_tot += self.columnWidth(i)
row_px = self.rowHeight(self.currentIndex()) row_px = self.rowHeight(self.currentIndex())
@ -175,22 +184,25 @@ class CompleterView(QTreeView):
# we should figure out the exact number of rows to allow # we should figure out the exact number of rows to allow
# inclusive of search bar and header "rows", in pixel terms. # inclusive of search bar and header "rows", in pixel terms.
window_h = self.window().height() window_h = self.window().height()
rows = round(window_h * 0.5 / row_px) - 4 rows = ceil(window_h / row_px) - 2
# TODO: the problem here is that this view widget is **not** resizing/scaling # TODO: the problem here is that this view widget is **not**
# when the parent layout is adjusted, not sure what exactly is up... # resizing/scaling when the parent layout is adjusted, not sure
# only "scale up" the results view when the window size has increased/ # what exactly is up... only "scale up" the results view
# when the window size has increased/
if not self._last_window_h or self._last_window_h < window_h: if not self._last_window_h or self._last_window_h < window_h:
self.setMaximumSize(self.width(), rows * row_px) self.setMaximumSize(self.width(), rows * row_px)
self.setMinimumSize(self.width(), rows * row_px) self.setMinimumSize(self.width(), rows * row_px)
#elif not self._last_window_h or self._last_window_h > window_h: # self.resize(self.width(), rows * row_px)
# self.setMinimumSize(self.width(), rows * row_px)
# self.setMaximumSize(self.width(), rows * row_px)
self.resize(self.width(), rows * row_px) self.resize(self.width(), rows * row_px)
self._last_window_h = window_h self._last_window_h = window_h
self.setFixedWidth(333)
# size to width of longest result seen thus far
# TODO: should we always dynamically scale to longest result?
if self.width() < col_w_tot:
self.setFixedWidth(col_w_tot)
self.update() self.update()
def is_selecting_d1(self) -> bool: def is_selecting_d1(self) -> bool:
@ -447,6 +459,7 @@ class SearchBar(Edit):
self.godwidget = godwidget self.godwidget = godwidget
super().__init__(parent, **kwargs) super().__init__(parent, **kwargs)
self.view: CompleterView = view self.view: CompleterView = view
godwidget._widgets[view.mode_name] = view
def show(self) -> None: def show(self) -> None:
super().show() super().show()