def _set_proper_position(self, parent): parent_geo = parent.geometry() pos = parent_geo.topLeft() if parent.parent() is None else parent.mapToGlobal( parent_geo.topLeft()) offset = 0 for child in parent.children(): if isinstance(child, MMessage) and child.isVisible(): offset = max(offset, child.y()) base = pos.y() + MMessage.default_config.get('top') target_x = pos.x() + parent_geo.width() / 2 - 100 target_y = (offset + 50) if offset else base self._pos_ani.setStartValue(QPoint(target_x, target_y - 40)) self._pos_ani.setEndValue(QPoint(target_x, target_y))
def do_layout(self, rect, test_only): x = rect.x() y = rect.y() line_height = 0 for item in self.item_list: wid = item.widget() space_x = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Horizontal) space_y = self.spacing() + wid.style().layoutSpacing(QSizePolicy.PushButton, QSizePolicy.PushButton, Qt.Vertical) next_x = x + item.sizeHint().width() + space_x if next_x - space_x > rect.right() and line_height > 0: x = rect.x() y = y + line_height + space_y next_x = x + item.sizeHint().width() + space_x line_height = 0 if not test_only: item.setGeometry(QRect(QPoint(x, y), item.sizeHint())) x = next_x line_height = max(line_height, item.sizeHint().height()) return y + line_height - rect.y()
def showPopup(self): """Override default showPopup. When set custom menu, show the menu instead.""" if self._has_custom_view or self._root_menu is None: super(MComboBox, self).showPopup() else: QComboBox.hidePopup(self) self._root_menu.popup(self.mapToGlobal(QPoint(0, self.height())))
def _slot_context_menu(self, point): context_menu = MMenu(parent=self) action_select_all = context_menu.addAction('Select All') action_select_none = context_menu.addAction('Select None') action_select_invert = context_menu.addAction('Select Invert') action_select_all.triggered.connect(functools.partial(self._slot_set_select, True)) action_select_none.triggered.connect(functools.partial(self._slot_set_select, False)) action_select_invert.triggered.connect(functools.partial(self._slot_set_select, None)) context_menu.exec_(QCursor.pos() + QPoint(10, 10))
def _get_center_position(self, parent): parent_geo = parent.geometry() pos = parent_geo.topLeft() \ if parent.parent() is None else parent.mapToGlobal(parent_geo.topLeft()) offset = 0 for child in parent.children(): if isinstance(child, MToast) and child.isVisible(): offset = max(offset, child.y()) target_x = pos.x() + parent_geo.width() / 2 - self.width() / 2 target_y = pos.y() + parent_geo.height() / 2 - self.height() / 2 self.setProperty('pos', QPoint(target_x, target_y))
def _set_proper_position(self): parent = self.parent() parent_geo = parent.geometry() if self._position == MDrawer.LeftPos: pos = parent_geo.topLeft( ) if parent.parent() is None else parent.mapToGlobal( parent_geo.topLeft()) pos -= self.window().geometry().topLeft() target_x = pos.x() target_y = pos.y() self.setFixedHeight(parent_geo.height()) self._pos_ani.setStartValue( QPoint(target_x - self.width(), target_y)) self._pos_ani.setEndValue(QPoint(target_x, target_y)) if self._position == MDrawer.RightPos: pos = parent_geo.topRight( ) if parent.parent() is None else parent.mapToGlobal( parent_geo.topRight()) pos -= self.window().geometry().topLeft() self.setFixedHeight(parent_geo.height()) target_x = pos.x() - self.width() target_y = pos.y() self._pos_ani.setStartValue( QPoint(target_x + self.width(), target_y)) self._pos_ani.setEndValue(QPoint(target_x, target_y)) if self._position == MDrawer.TopPos: pos = parent_geo.topLeft( ) if parent.parent() is None else parent.mapToGlobal( parent_geo.topLeft()) pos -= self.window().geometry().topLeft() self.setFixedWidth(parent_geo.width()) target_x = pos.x() target_y = pos.y() self._pos_ani.setStartValue( QPoint(target_x, target_y - self.height())) self._pos_ani.setEndValue(QPoint(target_x, target_y)) if self._position == MDrawer.BottomPos: pos = parent_geo.bottomLeft( ) if parent.parent() is None else parent.mapToGlobal( parent_geo.bottomLeft()) pos -= self.window().geometry().topLeft() self.setFixedWidth(parent_geo.width()) target_x = pos.x() target_y = pos.y() - self.height() self._pos_ani.setStartValue( QPoint(target_x, target_y + self.height())) self._pos_ani.setEndValue(QPoint(target_x, target_y))
def updateEditorGeometry(self, editor, option, index): editor.move( self.parent_widget.mapToGlobal( QPoint(option.rect.x(), option.rect.y() + option.rect.height())))