def _GenerateCurrentStatus(self) -> ClientGUIListStatus.ColumnListStatus: status = ClientGUIListStatus.ColumnListStatus() status.SetColumnListType(self._column_list_type) main_tlw = HG.client_controller.GetMainTLW() columns = [] header = self.header() num_columns = header.count() last_column_index = num_columns - 1 # ok, the big pain in the ass situation here is getting a precise last column size that is reproduced on next dialog launch # ultimately, with fuzzy sizing, style padding, scrollbars appearing, and other weirdness, the more precisely we try to define it, the more we will get dialogs that grow/shrink by a pixel each time # *therefore*, the actual solution here is to move to snapping with a decent snap distance. the user loses size setting precision, but we'll snap back to a decent size every time, compensating for fuzz LAST_COLUMN_SNAP_DISTANCE_CHARS = 5 for visual_index in range(num_columns): logical_index = header.logicalIndex(visual_index) column_type = self.headerItem().data(logical_index, QC.Qt.UserRole) width_pixels = header.sectionSize(logical_index) shown = not header.isSectionHidden(logical_index) if visual_index == last_column_index: if self.verticalScrollBar().isVisible(): width_pixels += max( 0, min(self.verticalScrollBar().width(), 20)) width_chars = ClientGUIFunctions.ConvertPixelsToTextWidth( main_tlw, width_pixels) if visual_index == last_column_index: # here's the snap magic width_chars = round( width_chars // LAST_COLUMN_SNAP_DISTANCE_CHARS ) * LAST_COLUMN_SNAP_DISTANCE_CHARS columns.append((column_type, width_chars, shown)) status.SetColumns(columns) status.SetSort(self._sort_column_type, self._sort_asc) return status
def _GenerateCurrentStatus(self) -> ClientGUIListStatus.ColumnListStatus: status = ClientGUIListStatus.ColumnListStatus() status.SetColumnListType(self._column_list_type) main_tlw = HG.client_controller.GetMainTLW() columns = [] header = self.header() num_columns = header.count() last_column_index = num_columns - 1 for visual_index in range(num_columns): logical_index = header.logicalIndex(visual_index) column_type = self.headerItem().data(logical_index, QC.Qt.UserRole) width_pixels = header.sectionSize(logical_index) shown = not header.isSectionHidden(logical_index) # if the scrollbar is in place, then when we initialise, next time, we will want to include that extra space in our final column recommended size # might need to update this to be 'last non-hidden section', rather than 'last 'visual' section' if visual_index == last_column_index and self.verticalScrollBar( ).isVisible(): width_pixels += self.verticalScrollBar().width() width_chars = ClientGUIFunctions.ConvertPixelsToTextWidth( main_tlw, width_pixels) columns.append((column_type, width_chars, shown)) status.SetColumns(columns) status.SetSort(self._sort_column_type, self._sort_asc) return status
def _GenerateCurrentStatus(self) -> ClientGUIListStatus.ColumnListStatus: status = ClientGUIListStatus.ColumnListStatus() status.SetColumnListType(self._column_list_type) main_tlw = HG.client_controller.GetMainTLW() columns = [] header = self.header() num_columns = header.count() last_column_index = num_columns - 1 # ok, the big pain in the ass situation here is getting a precise last column size that is reproduced on next dialog launch # ultimately, with fuzzy sizing, style padding, scrollbars appearing, and other weirdness, the more precisely we try to define it, the more we will get dialogs that grow/shrink by a pixel each time # *therefore*, the actual solution here is to move to snapping with a decent snap distance. the user loses size setting precision, but we'll snap back to a decent size every time, compensating for fuzz LAST_COLUMN_SNAP_DISTANCE_CHARS = 5 total_fixed_columns_width = 0 for visual_index in range(num_columns): logical_index = header.logicalIndex(visual_index) column_type = self.headerItem().data(logical_index, QC.Qt.UserRole) width_pixels = header.sectionSize(logical_index) shown = not header.isSectionHidden(logical_index) if visual_index == last_column_index: # testing if scrollbar is visible is unreliable, since we don't know if it is laid out correct yet (we could be doing that now!) # so let's just hack it width_pixels = self.width() - (self.frameWidth() * 2) - total_fixed_columns_width else: total_fixed_columns_width += width_pixels width_chars = ClientGUIFunctions.ConvertPixelsToTextWidth( main_tlw, width_pixels) if visual_index == last_column_index: # here's the snap magic. final width_chars is always a multiple of 5 width_chars = round( width_chars / LAST_COLUMN_SNAP_DISTANCE_CHARS ) * LAST_COLUMN_SNAP_DISTANCE_CHARS columns.append((column_type, width_chars, shown)) status.SetColumns(columns) status.SetSort(self._sort_column_type, self._sort_asc) return status