def __init__(self, parent=None): super(_TestClass, self).__init__(parent) geo = QApplication.desktop().screenGeometry() self.setGeometry(geo.width() / 4, geo.height() / 4, geo.width() / 2, geo.height() / 2)
def __init__(self, parent=None): super(CardExample, self).__init__(parent) geo = QApplication.desktop().screenGeometry() self.setGeometry(geo.width() / 4, geo.height() / 4, geo.width() / 1.5, geo.height() / 2) self._init_ui()
def test_cursor_mixin(qtbot): @mixin.cursor_mixin class _TestClass(QPushButton): def __init__(self, parent=None): super(_TestClass, self).__init__(parent) geo = QApplication.desktop().screenGeometry() self.setGeometry(geo.width() / 4, geo.height() / 4, geo.width() / 2, geo.height() / 2) main_widget = QWidget() button_test = _TestClass() button_normal = QPushButton() test_lay = QVBoxLayout() test_lay.addWidget(button_test) test_lay.addWidget(button_normal) main_widget.setLayout(test_lay) qtbot.addWidget(main_widget) main_widget.show() button_test.setEnabled(False) assert QApplication.overrideCursor() is None # Not override cursor qtbot.mouseMove(button_test) # mouse enter def check_cursor(): assert QApplication.overrideCursor() is not None assert QApplication.overrideCursor().shape() == Qt.ForbiddenCursor qtbot.waitUntil(check_cursor) qtbot.mouseMove(button_normal) # mouse leave def check_cursor(): assert QApplication.overrideCursor() is None # Restore override cursor qtbot.waitUntil(check_cursor) button_test.setEnabled(True) qtbot.mouseMove(button_test) # mouse enter def check_cursor(): assert QApplication.overrideCursor() is not None assert QApplication.overrideCursor().shape() == Qt.PointingHandCursor qtbot.waitUntil(check_cursor) qtbot.mouseMove(button_normal) # mouse leave def check_cursor(): assert QApplication.overrideCursor() is None # Restore override cursor qtbot.waitUntil(check_cursor)
def _slot_show_detail(self): dialog = QTextEdit(self) dialog.setReadOnly(True) geo = QApplication.desktop().screenGeometry() dialog.setGeometry(geo.width() / 2, geo.height() / 2, geo.width() / 4, geo.height() / 4) dialog.setWindowTitle(self.tr('Error Detail Information')) dialog.setText(self.property('history')) dialog.setWindowFlags(Qt.Dialog) dialog.show()
def __init__(self, parent=None): super(CardExample, self).__init__(parent) self.setWindowTitle('Examples for MCard') geo = QApplication.desktop().screenGeometry() width = float(geo.width()) height = float(geo.height()) x = int(width / 4) y = int(height / 4) w = int(width / 1.5) h = int(height / 2) self.setGeometry(x,y,w,h) self._init_ui()
def __init__(self, parent=None): super(AddDelete, self).__init__(parent) self.tag_lay = MFlowLayout() tag1 = MTag('Unremoveable') tag2 = MTag('Tag2').closeable() tag3 = MTag('Tag3').closeable() add_tag = MNewTag('New Tag') add_tag.sig_add_tag.connect(self.slot_add_tag) self.tag_lay.addWidget(tag1) self.tag_lay.addWidget(tag2) self.tag_lay.addWidget(tag3) self.tag_lay.addWidget(add_tag) main_lay = QHBoxLayout() main_lay.addLayout(self.tag_lay) self.setLayout(main_lay) geo = QApplication.desktop().screenGeometry() self.setGeometry(geo.width() / 4, geo.height() / 4, geo.width() / 2, geo.height() / 2)
class Basic(QWidget): def __init__(self, parent=None): super(Basic, self).__init__(parent) main_lay = QHBoxLayout() tag1 = MTag('Tag 1') tag2 = MTag('Clickable Tag').clickable() tag3 = MTag('Closeable Tag').closeable() tag2.sig_clicked.connect( functools.partial(self.slot_handle_signal, 'sig_clicked')) tag3.sig_closed.connect( functools.partial(self.slot_handle_signal, 'sig_closed')) main_lay.addWidget(tag1) main_lay.addWidget(tag2) main_lay.addWidget(tag3) main_lay.addStretch() self.setLayout(main_lay) @Slot(str) def slot_handle_signal(self, text): print 'Signal {} emitted.'.format(text) if __name__ == '__main__': import sys app = QApplication(sys.argv) test = Basic() test.show() sys.exit(app.exec_())
def check_cursor(): assert QApplication.overrideCursor() is None # Restore override cursor
def check_cursor(): assert QApplication.overrideCursor() is not None assert QApplication.overrideCursor().shape() == Qt.PointingHandCursor
def check_cursor(): assert QApplication.overrideCursor() is not None assert QApplication.overrideCursor().shape() == Qt.ForbiddenCursor
def __init__(self, title, position='right', closable=True, parent=None): super(MDrawer, self).__init__(parent) self.setObjectName('message') # self.setWindowFlags(Qt.Popup ) # self.setWindowFlags( # Qt.FramelessWindowHint | Qt.Popup | Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_StyledBackground) self._title_label = MLabel(parent=self).h4() # self._title_label.set_elide_mode(Qt.ElideRight) self._title_label.setText(title) self._close_button = MToolButton( parent=self).icon_only().svg('close_line.svg').small() self._close_button.clicked.connect(self.close) self._close_button.setVisible(closable or False) _title_lay = QHBoxLayout() _title_lay.addWidget(self._title_label) _title_lay.addStretch() _title_lay.addWidget(self._close_button) self._button_lay = QHBoxLayout() self._button_lay.addStretch() self._scroll_area = QScrollArea() self._main_lay = QVBoxLayout() self._main_lay.addLayout(_title_lay) self._main_lay.addWidget(MDivider()) self._main_lay.addWidget(self._scroll_area) self._main_lay.addWidget(MDivider()) self._main_lay.addLayout(self._button_lay) self.setLayout(self._main_lay) self._position = position self._close_timer = QTimer(self) self._close_timer.setSingleShot(True) self._close_timer.timeout.connect(self.close) self._close_timer.timeout.connect(self.sig_closed) self._close_timer.setInterval(300) self._is_first_close = True self._pos_ani = QPropertyAnimation(self) self._pos_ani.setTargetObject(self) self._pos_ani.setEasingCurve(QEasingCurve.OutCubic) self._pos_ani.setDuration(300) self._pos_ani.setPropertyName('pos') self._opacity_ani = QPropertyAnimation() self._opacity_ani.setTargetObject(self) self._opacity_ani.setDuration(300) self._opacity_ani.setEasingCurve(QEasingCurve.OutCubic) self._opacity_ani.setPropertyName('windowOpacity') self._opacity_ani.setStartValue(0.0) self._opacity_ani.setEndValue(1.0) # self._shadow_effect = QGraphicsDropShadowEffect(self) # color = dayu_theme.red # self._shadow_effect.setColor(color) # self._shadow_effect.setOffset(0, 0) # self._shadow_effect.setBlurRadius(5) # self._shadow_effect.setEnabled(False) # self.setGraphicsEffect(self._shadow_effect) self.app = QApplication.instance() self.app.installEventFilter(self) self.protect_time = time.time()
def slot_left_clicked(self, start_index): button = QApplication.mouseButtons() if button == Qt.LeftButton: real_index = self.sort_filter_model.mapToSource(start_index) self.sig_left_clicked.emit(real_index)