def _init_ui(self): standalone_lay = QHBoxLayout() standalone_lay.addWidget(MBadge.count(0)) standalone_lay.addWidget(MBadge.count(20)) standalone_lay.addWidget(MBadge.count(100)) standalone_lay.addWidget(MBadge.dot(True)) standalone_lay.addWidget(MBadge.text('new')) standalone_lay.addStretch() button = MToolButton().svg('trash_line.svg') avatar = MAvatar.large(MPixmap('avatar.png')) button_alert = MToolButton().svg('alert_fill.svg').large() badge_1 = MBadge.dot(True, widget=button) badge_2 = MBadge.dot(True, widget=avatar) badge_3 = MBadge.dot(True, widget=button_alert) button.clicked.connect(lambda: badge_1.set_dayu_dot(False)) spin_box = MSpinBox() spin_box.setRange(0, 9999) spin_box.valueChanged.connect(badge_3.set_dayu_count) spin_box.setValue(1) self.register_field('button1_selected', u'北京') menu1 = MMenu() menu1.set_data([u'北京', u'上海', u'广州', u'深圳']) select1 = MComboBox() select1.set_menu(menu1) self.bind('button1_selected', select1, 'value', signal='sig_value_changed') badge_hot = MBadge.text('hot', widget=MLabel(u'你的理想城市 ')) sub_lay1 = QHBoxLayout() sub_lay1.addWidget(badge_1) sub_lay1.addWidget(badge_2) sub_lay1.addWidget(badge_3) sub_lay1.addStretch() sub_lay2 = QHBoxLayout() sub_lay2.addWidget(badge_hot) sub_lay2.addWidget(select1) sub_lay2.addStretch() main_lay = QVBoxLayout() main_lay.addWidget(MDivider('use standalone')) main_lay.addLayout(standalone_lay) main_lay.addWidget(MDivider('different type')) main_lay.addLayout(sub_lay1) main_lay.addWidget(spin_box) main_lay.addWidget(MDivider('different type')) main_lay.addLayout(sub_lay2) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): standalone_lay = QtWidgets.QHBoxLayout() standalone_lay.addWidget(MBadge.count(0)) standalone_lay.addWidget(MBadge.count(20)) standalone_lay.addWidget(MBadge.count(100)) standalone_lay.addWidget(MBadge.dot(True)) standalone_lay.addWidget(MBadge.text("new")) standalone_lay.addStretch() button = MToolButton().svg("trash_line.svg") avatar = MAvatar.large(MPixmap("avatar.png")) button_alert = MToolButton().svg("alert_fill.svg").large() badge_1 = MBadge.dot(True, widget=button) badge_2 = MBadge.dot(True, widget=avatar) badge_3 = MBadge.dot(True, widget=button_alert) button.clicked.connect(lambda: badge_1.set_dayu_dot(False)) spin_box = MSpinBox() spin_box.setRange(0, 9999) spin_box.valueChanged.connect(badge_3.set_dayu_count) spin_box.setValue(1) self.register_field("button1_selected", "北京") menu1 = MMenu(parent=self) menu1.set_data(["北京", "上海", "广州", "深圳"]) select1 = MComboBox() select1.set_menu(menu1) self.bind("button1_selected", select1, "value", signal="sig_value_changed") badge_hot = MBadge.text("hot", widget=MLabel("你的理想城市 ")) sub_lay1 = QtWidgets.QHBoxLayout() sub_lay1.addWidget(badge_1) sub_lay1.addWidget(badge_2) sub_lay1.addWidget(badge_3) sub_lay1.addStretch() sub_lay2 = QtWidgets.QHBoxLayout() sub_lay2.addWidget(badge_hot) sub_lay2.addWidget(select1) sub_lay2.addStretch() main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("use standalone")) main_lay.addLayout(standalone_lay) main_lay.addWidget(MDivider("different type")) main_lay.addLayout(sub_lay1) main_lay.addWidget(spin_box) main_lay.addWidget(MDivider("different type")) main_lay.addLayout(sub_lay2) main_lay.addStretch() self.setLayout(main_lay)
def __init__(self): super(CenterWindow,self).__init__() self.setObjectName("CenterWindow") self.fileList = [] # 保存当前选择标签下的文件列表 self.tag = "" # 保存当前标签 self.tableWidget_show = True # tableWidget窗口是否显示 self.row = 0 # 定位添加标签 self.column = 0 self.setupUI() # 设置tablewidget self.tableWidget = self.ui.findChild(QTableWidget, "tableWidget") self.tableWidget.setMaximumHeight(Data.getWindowHeight()/5) self.setTableWidget() self.tableWidget.setStyleSheet(Data.getQSS()) self.tableWidget.setStyleSheet("background-color: #323232") self.searchWidget = self.ui.findChild(QWidget, "widget_2") self.search_engine_line_edit = MLineEdit().search_engine().large() dayu_theme.apply(self.search_engine_line_edit) self.searchWidget.setLayout(QHBoxLayout()) self.searchWidget.layout().addWidget(self.search_engine_line_edit) self.slider = MSlider(Qt.Horizontal) self.slider.setMaximumWidth(Data.getWindowWidth()/4) self.slider.setValue(50) self.slider.setRange(1, 100) dayu_theme.apply(self.slider) self.searchWidget.layout().addWidget(self.slider) self.button_tag = MToolButton().svg('detail_line.svg').icon_only() self.button_tag.setEnabled(True) self.button_del = MToolButton().svg('trash_line.svg').icon_only() self.button_del.setCheckable(True) dayu_theme.apply(self.button_del) dayu_theme.apply(self.button_tag) self.searchWidget.layout().addWidget(self.button_tag) self.searchWidget.layout().addWidget(self.button_del) self.slider.valueChanged.connect(self.changeBtnSize) self.button_tag.clicked.connect(self.showTableWidget) self.button_del.clicked.connect(self.deleteTag) self.search_engine_line_edit.returnPressed.connect(self.on_searchBtn_click) self.setThread()
def __init__(self, view_type=None, parent=None): super(MItemViewSet, self).__init__(parent) self.main_lay = QtWidgets.QVBoxLayout() self.main_lay.setSpacing(5) self.main_lay.setContentsMargins(0, 0, 0, 0) self.sort_filter_model = MSortFilterModel() self.source_model = MTableModel() self.sort_filter_model.setSourceModel(self.source_model) view_class = view_type or MItemViewSet.TableViewType self.item_view = view_class() self.item_view.doubleClicked.connect(self.sig_double_clicked) self.item_view.pressed.connect(self.slot_left_clicked) self.item_view.setModel(self.sort_filter_model) self._search_line_edit = MLineEdit().search().small() self._search_attr_button = ( MToolButton().icon_only().svg("down_fill.svg").small()) self._search_line_edit.set_prefix_widget(self._search_attr_button) self._search_line_edit.textChanged.connect( self.sort_filter_model.set_search_pattern) self._search_line_edit.setVisible(False) self._search_lay = QtWidgets.QHBoxLayout() self._search_lay.setContentsMargins(0, 0, 0, 0) self._search_lay.addStretch() self._search_lay.addWidget(self._search_line_edit) self.main_lay.addLayout(self._search_lay) self.main_lay.addWidget(self.item_view) self.setLayout(self.main_lay)
def _init_ui(self): # 工具 item_list = [ {'text': u'文件', 'svg': 'folder_line.svg', 'clicked': self.openFile}, {'text': u'编辑', 'svg': 'edit_line.svg', 'clicked': self.editFile}, {'text': u'关于', 'svg': 'warning_line.svg', 'clicked': self.showAbout}, ] tool_bar = MMenuTabWidget() tool_bar.tool_bar_insert_widget(MLabel('Zeus').h4().secondary().strong()) self.user_toolButton = MToolButton().large() pixmap = QPixmap(file_path + "\\res\\headPortrial\\user_default.png") self.user_toolButton.setIcon(pixmap) tool_bar.tool_bar_append_widget( MBadge.dot(show=False, widget=self.user_toolButton)) self.label = MLabel(u"未登录") tool_bar.tool_bar_append_widget( MBadge.dot(show=False, widget=self.label)) for index, data_dict in enumerate(item_list): tool_bar.add_menu(data_dict, index) main_lay = QHBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.addWidget(tool_bar) self.setLayout(main_lay) self.layout().setSpacing(0) self.layout().setContentsMargins(0, 0, 0, 0) self.user_toolButton.clicked.connect(self.setUser)
def __init__(self, title=None, image=None, size=None, extra=None, type=None, parent=None): super(MCard, self).__init__(parent=parent) self.setAttribute(Qt.WA_StyledBackground) map_label = { dayu_theme.large: (MLabel.h2, 20), dayu_theme.medium: (MLabel.h3, 15), dayu_theme.small: (MLabel.h4, 10), } self._title_label = map_label.get(size or dayu_theme.default_size)[0](text=title) padding = map_label.get(size or dayu_theme.default_size)[-1] self._title_layout = QHBoxLayout() self._title_layout.setContentsMargins(padding, padding, padding, padding) if image: self._title_icon = MAvatar(image=image, size=size) self._title_layout.addWidget(self._title_icon) self._title_layout.addWidget(self._title_label) self._title_layout.addStretch() if extra: self._extra_button = MToolButton(type=MToolButton.IconOnlyType, icon=MIcon('more.svg')) self._title_layout.addWidget(self._extra_button) self._content_layout = QVBoxLayout() self._main_lay = QVBoxLayout() self._main_lay.setSpacing(0) self._main_lay.setContentsMargins(1, 1, 1, 1) if title: self._main_lay.addLayout(self._title_layout) self._main_lay.addWidget(MDivider()) self._main_lay.addLayout(self._content_layout) self.setLayout(self._main_lay)
def __init__(self, text="New Tag", parent=None): super(MNewTag, self).__init__(parent) self.setAttribute(Qt.WA_StyledBackground) self._add_button = MToolButton().text_beside_icon().small().svg( "add_line.svg") self._add_button.setText(text) self._add_button.clicked.connect(self._slot_show_edit) self._line_edit = MLineEdit().small() self._line_edit.returnPressed.connect(self._slot_return_pressed) self._line_edit.setVisible(False) self._line_edit.installEventFilter(self) self._main_lay = QGridLayout() self._main_lay.setContentsMargins(3, 3, 3, 3) self._main_lay.addWidget(self._add_button, 0, 0) self._main_lay.addWidget(self._line_edit, 0, 0) self.setLayout(self._main_lay) scale_x, _ = get_scale_factor() style = QssTemplate(""" MNewTag{ border: @border@unit dashed @border_color; } MNewTag MToolButton:hover{ border:none; } """) self.setStyleSheet( style.substitute( border_color=utils.fade_color(dayu_theme.secondary_text_color, "35%"), unit=dayu_theme.unit, border=1 * scale_x, ))
def __init__(self, text='New Tag', parent=None): super(MNewTag, self).__init__(parent) self.setAttribute(Qt.WA_StyledBackground) self._add_button = MToolButton().text_beside_icon().tiny().svg( 'add_line.svg') self._add_button.setText(text) self._add_button.clicked.connect(self._slot_show_edit) self._line_edit = MLineEdit().tiny() self._line_edit.returnPressed.connect(self._slot_return_pressed) self._line_edit.setVisible(False) self._line_edit.installEventFilter(self) self._main_lay = QGridLayout() self._main_lay.setContentsMargins(3, 3, 3, 3) self._main_lay.addWidget(self._add_button, 0, 0) self._main_lay.addWidget(self._line_edit, 0, 0) self.setLayout(self._main_lay) style = QssTemplate(''' MNewTag{ border: 1px dashed @border_color; } MNewTag MToolButton:hover{ border:none; } ''') self.setStyleSheet(style.substitute(vars(dayu_theme)))
def add_item(self, data_dict, index=None): """Add a item""" button = MToolButton() button.setText(data_dict.get("text")) if data_dict.get("svg"): button.svg(data_dict.get("svg")) if data_dict.get("tooltip"): button.setProperty("toolTip", data_dict.get("tooltip")) if data_dict.get("clicked"): button.clicked.connect(data_dict.get("clicked")) if data_dict.get("text"): if data_dict.get("svg") or data_dict.get("icon"): button.text_beside_icon() else: button.text_only() else: button.icon_only() if self._button_group.buttons(): separator = MLabel(self._separator).secondary() self._label_list.append(separator) self._main_layout.insertWidget(self._main_layout.count() - 1, separator) self._main_layout.insertWidget(self._main_layout.count() - 1, button) if index is None: self._button_group.addButton(button) else: self._button_group.addButton(button, index)
def _init_ui(self): item_list = [ { "text": "Overview", "svg": "home_line.svg", "clicked": functools.partial(MMessage.info, "首页", parent=self), }, { "text": "我的", "svg": "user_line.svg", "clicked": functools.partial(MMessage.info, "编辑账户", parent=self), }, { "text": "Notice", "svg": "alert_line.svg", "clicked": functools.partial(MMessage.info, "查看通知", parent=self), }, ] tool_bar = MMenuTabWidget() tool_bar_huge = MMenuTabWidget() tool_bar_huge.set_dayu_size(dayu_theme.huge) tool_bar_huge_v = MMenuTabWidget(orientation=QtCore.Qt.Vertical) tool_bar_huge_v.set_dayu_size(dayu_theme.huge) tool_bar.tool_bar_insert_widget( MLabel("DaYu").h4().secondary().strong()) tool_bar_huge.tool_bar_insert_widget( MLabel("DaYu").h4().secondary().strong()) dayu_icon = MLabel("DaYu").h4().secondary().strong() dayu_icon.setContentsMargins(10, 10, 10, 10) tool_bar_huge_v.tool_bar_insert_widget(dayu_icon) tool_bar.tool_bar_append_widget( MBadge.dot( show=True, widget=MToolButton().icon_only().svg("user_fill.svg").large())) for index, data_dict in enumerate(item_list): tool_bar.add_menu(data_dict, index) tool_bar_huge.add_menu(data_dict, index) tool_bar_huge_v.add_menu(data_dict, index) tool_bar.tool_button_group.set_dayu_checked(0) tool_bar_huge.tool_button_group.set_dayu_checked(0) tool_bar_huge_v.tool_button_group.set_dayu_checked(0) main_lay = QtWidgets.QVBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.addWidget(MLabel("Menu Tab Widget (Large)")) main_lay.addWidget(tool_bar) main_lay.addWidget(MLabel("Menu Tab Widget (Huge)")) main_lay.addWidget(tool_bar_huge) main_lay.addWidget(MLabel("Menu Vertical Tab Widget (Huge)")) main_lay.addWidget(tool_bar_huge_v) self.setLayout(main_lay)
def __init__(self, cover=None, avatar=None, title=None, description=None, extra=False, parent=None): super(MMeta, self).__init__(parent) self.setAttribute(Qt.WA_StyledBackground) # self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) self._cover_label = QLabel() self._avatar = MAvatar() self._title_label = MLabel.h4() # self._title_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.MinimumExpanding) self._description_label = MLabel.help() # self._description_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.MinimumExpanding) self._description_label.setWordWrap(True) self._title_layout = QHBoxLayout() self._title_layout.addWidget(self._title_label) self._title_layout.addStretch() if extra: self._extra_button = MToolButton(type=MToolButton.IconOnlyType, icon=MIcon('more.svg')) self._title_layout.addWidget(self._extra_button) content_lay = QFormLayout() content_lay.setContentsMargins(5, 5, 5, 5) content_lay.addRow(self._avatar, self._title_layout) content_lay.addRow(self._description_label) self._button_layout = QHBoxLayout() main_lay = QVBoxLayout() main_lay.setSpacing(0) main_lay.setContentsMargins(1, 1, 1, 1) main_lay.addWidget(self._cover_label) main_lay.addLayout(content_lay) main_lay.addLayout(self._button_layout) main_lay.addStretch() self.setLayout(main_lay) self._cover_label.setFixedSize(QSize(200, 200))
def __init__(self, text='', parent=None, flags=0): super(MAlert, self).__init__(parent, flags) self.setAttribute(Qt.WA_StyledBackground) self._icon_label = MAvatar() self._icon_label.set_dayu_size(dayu_theme.tiny) self._content_label = MLabel().secondary() self._close_button = MToolButton().svg( 'close_line.svg').tiny().icon_only() self._close_button.clicked.connect( functools.partial(self.setVisible, False)) self._main_lay = QHBoxLayout() self._main_lay.setContentsMargins(8, 8, 8, 8) self._main_lay.addWidget(self._icon_label) self._main_lay.addWidget(self._content_label) self._main_lay.addStretch() self._main_lay.addWidget(self._close_button) self.setLayout(self._main_lay) self.set_show_icon(True) self.set_closeable(False) self._dayu_type = None self._dayu_text = None self.set_dayu_type(MAlert.InfoType) self.set_dayu_text(text)
def search(self): """Add a search icon button for MLineEdit.""" suffix_button = MToolButton().icon_only().svg('close_line.svg') suffix_button.clicked.connect(self.clear) self.set_suffix_widget(suffix_button) self.setPlaceholderText(self.tr('Enter key word to search...')) return self
def __init__(self, text, duration=None, dayu_type=None, closable=False, parent=None): super(MMessage, self).__init__(parent) self.setObjectName('message') self.setWindowFlags( Qt.FramelessWindowHint | Qt.Dialog | Qt.WA_TranslucentBackground | Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_StyledBackground) if dayu_type == MMessage.LoadingType: _icon_label = MLoading.tiny() else: _icon_label = MAvatar.tiny() current_type = dayu_type or MMessage.InfoType _icon_label.set_dayu_image(MPixmap('{}_fill.svg'.format(current_type), vars(dayu_theme).get(current_type + '_color'))) self._content_label = MLabel(parent=self) # self._content_label.set_elide_mode(Qt.ElideMiddle) self._content_label.setText(text) self._close_button = MToolButton(parent=self).icon_only().svg('close_line.svg').tiny() self._close_button.clicked.connect(self.close) self._close_button.setVisible(closable or False) self._main_lay = QHBoxLayout() self._main_lay.addWidget(_icon_label) self._main_lay.addWidget(self._content_label) self._main_lay.addStretch() self._main_lay.addWidget(self._close_button) self.setLayout(self._main_lay) _close_timer = QTimer(self) _close_timer.setSingleShot(True) _close_timer.timeout.connect(self.close) _close_timer.timeout.connect(self.sig_closed) _close_timer.setInterval((duration or self.default_config.get('duration')) * 1000) _ani_timer = QTimer(self) _ani_timer.timeout.connect(self._fade_out) _ani_timer.setInterval((duration or self.default_config.get('duration')) * 1000 - 300) _close_timer.start() _ani_timer.start() 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._set_proper_position(parent) self._fade_int()
def _init_ui(self): main_lay = QtWidgets.QVBoxLayout() tab_center = MLineTabWidget() tab_center.add_tab( MLabel("test 1 " * 10), {"text": "Tab 1", "svg": "user_line.svg"} ) tab_center.add_tab(MLabel("test 2 " * 10), {"svg": "calendar_line.svg"}) tab_center.add_tab(MLabel("test 3 " * 10), "Tab 3") tab_center.tool_button_group.set_dayu_checked(0) tab_left = MLineTabWidget(alignment=QtCore.Qt.AlignLeft) tab_left.add_tab(MLabel("test 1 " * 10), "Tab 1") tab_left.add_tab(MLabel("test 2 " * 10), "Tab 2") tab_left.add_tab(MLabel("test 3 " * 10), "Tab 3") tab_left.tool_button_group.set_dayu_checked(0) tab_right = MLineTabWidget(alignment=QtCore.Qt.AlignRight) tab_right.add_tab(MLabel("test 1 " * 10), "Tab 1") tab_right.add_tab(MLabel("test 2 " * 10), "Tab 2") tab_right.add_tab(MLabel("test 3 " * 10), "Tab 3") tab_right.tool_button_group.set_dayu_checked(0) tab_huge = MLineTabWidget() tab_huge.set_dayu_size(dayu_theme.huge) tab_huge.add_tab( MLabel("test 1 " * 10), {"text": "Tab 1", "svg": "user_line.svg"} ) tab_huge.add_tab(MLabel("test 2 " * 10), "Tab 2") tab_huge.add_tab(MLabel("test 3 " * 10), "Tab 3") tab_huge.tool_button_group.set_dayu_checked(0) tab_append_insert = MLineTabWidget() tab_append_insert.add_tab( MLabel("test 1 " * 10), {"text": "Tab 1", "svg": "user_line.svg"} ) tab_append_insert.add_tab(MLabel("test 2 " * 10), "Tab 2") tab_append_insert.add_tab(MLabel("test 3 " * 10), "Tab 3") tab_append_insert.tool_button_group.set_dayu_checked(0) tab_append_insert.insert_widget(MLabel("Insert Label").h4()) tab_append_insert.append_widget( MToolButton().svg("refresh_line.svg").icon_only() ) main_lay.addWidget(MDivider("Center")) main_lay.addWidget(tab_center) main_lay.addSpacing(20) main_lay.addWidget(MDivider("Left")) main_lay.addWidget(tab_left) main_lay.addSpacing(20) main_lay.addWidget(MDivider("Right")) main_lay.addWidget(tab_right) main_lay.addSpacing(20) main_lay.addWidget(MDivider("Huge")) main_lay.addWidget(tab_huge) main_lay.addWidget(MDivider("append_widget/insert_widget")) main_lay.addWidget(tab_append_insert) main_lay.addStretch() self.setLayout(main_lay)
def __init__(self, title, position="right", closable=True, parent=None): super(MDrawer, self).__init__(parent) self.setObjectName("message") self.setWindowFlags(QtCore.Qt.Popup) # self.setWindowFlags( # Qt.FramelessWindowHint | Qt.Popup | Qt.WA_TranslucentBackground) self.setAttribute(QtCore.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) self._title_extra_lay = QtWidgets.QHBoxLayout() _title_lay = QtWidgets.QHBoxLayout() _title_lay.addWidget(self._title_label) _title_lay.addStretch() _title_lay.addLayout(self._title_extra_lay) _title_lay.addWidget(self._close_button) self._bottom_lay = QtWidgets.QHBoxLayout() self._bottom_lay.addStretch() self._scroll_area = QtWidgets.QScrollArea() self._scroll_area.setWidgetResizable(True) self._main_lay = QtWidgets.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._bottom_lay) self.setLayout(self._main_lay) self._position = position self._close_timer = QtCore.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 = QtCore.QPropertyAnimation(self) self._pos_ani.setTargetObject(self) self._pos_ani.setEasingCurve(QtCore.QEasingCurve.OutCubic) self._pos_ani.setDuration(300) self._pos_ani.setPropertyName(b"pos") self._opacity_ani = QtCore.QPropertyAnimation() self._opacity_ani.setTargetObject(self) self._opacity_ani.setDuration(300) self._opacity_ani.setEasingCurve(QtCore.QEasingCurve.OutCubic) self._opacity_ani.setPropertyName(b"windowOpacity") self._opacity_ani.setStartValue(0.0) self._opacity_ani.setEndValue(1.0)
def setupUI(self): self.setMinimumSize(Data.getWindowWidth() / 4.7, Data.getWindowHeight() / 2) self.setMaximumSize(Data.getWindowWidth() / 4.7, Data.getWindowHeight() / 2) self.setWindowModality(Qt.ApplicationModal) Data.setWindowCenter(self) self.setLayout(QVBoxLayout()) btn = MPushButton("SIGNAL IN") btn.setIcon(QIcon(file_path + r"\res\ZeusDesign\a.png")) self.layout().addWidget(btn) self.layout().addWidget(MDivider()) self.line_edit_name = MLineEdit() self.line_edit_name.setPlaceholderText('username') self.line_edit_name.set_prefix_widget( MToolButton().svg('user_line.svg').icon_only()) self.line_edit_password = MLineEdit() self.line_edit_password.setPlaceholderText('password') self.line_edit_password.setEchoMode(QLineEdit.Password) self.line_edit_password.set_prefix_widget( MToolButton().svg('confirm_line.svg').icon_only()) self.layout().addWidget(self.line_edit_name) self.layout().addWidget(self.line_edit_password) self.layout().addWidget(MDivider()) self.btn_sign_in = MPushButton(u'登录').large().primary() self.layout().addWidget(self.btn_sign_in) self.btn_sign_up = MPushButton(u'注册').large().primary() self.layout().addWidget(self.btn_sign_up) dayu_theme.background_color = "#262626" dayu_theme.apply(self) self.layout().setContentsMargins(20, 40, 20, 40) self.btn_sign_up.clicked.connect(self.on_sigin_up_click) self.btn_sign_in.clicked.connect(self.on_sigin_in_click) self.setWindowTitle(u"登录界面")
def _init_ui(self): size_lay = QtWidgets.QVBoxLayout() sub_lay1 = QtWidgets.QHBoxLayout() sub_lay1.addWidget( MToolButton().svg("left_line.svg").icon_only().huge()) sub_lay1.addWidget( MToolButton().svg("right_line.svg").icon_only().large()) sub_lay1.addWidget(MToolButton().svg("up_line.svg").icon_only()) sub_lay1.addWidget( MToolButton().svg("up_line.svg").icon_only().small()) sub_lay1.addWidget( MToolButton().svg("down_line.svg").icon_only().tiny()) sub_lay1.addStretch() size_lay.addLayout(sub_lay1) button2 = MToolButton().svg("detail_line.svg").icon_only() button2.setEnabled(False) button7 = MToolButton().svg("trash_line.svg").icon_only() button7.setCheckable(True) state_lay = QtWidgets.QHBoxLayout() state_lay.addWidget(button2) state_lay.addWidget(button7) state_lay.addStretch() button_trash = MToolButton().svg("trash_line.svg").text_beside_icon() button_trash.setText("Delete") button_login = MToolButton().svg("user_line.svg").text_beside_icon() button_login.setText("Login") button_lay = QtWidgets.QHBoxLayout() button_lay.addWidget(button_trash) button_lay.addWidget(button_login) sub_lay2 = QtWidgets.QHBoxLayout() sub_lay2.addWidget(button2) sub_lay2.addWidget(button7) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("different button_size")) main_lay.addLayout(size_lay) main_lay.addWidget(MDivider("disabled & checkable")) main_lay.addLayout(state_lay) main_lay.addWidget(MDivider("type=normal")) main_lay.addLayout(button_lay) main_lay.addStretch() self.setLayout(main_lay)
def create_button(self, data_dict): button = MToolButton() if data_dict.get("svg"): button.svg(data_dict.get("svg")) if data_dict.get("text"): if data_dict.get("svg") or data_dict.get("icon"): button.text_beside_icon() else: button.text_only() else: button.icon_only() return button
def create_button(self, data_dict): button = MToolButton() if data_dict.get('svg'): button.svg(data_dict.get('svg')) if data_dict.get('text'): if data_dict.get('svg') or data_dict.get('icon'): button.text_beside_icon() else: button.text_only() else: button.icon_only() return button
def __init__(self, title="", expand=False, widget=None, closable=False, parent=None): super(MSectionItem, self).__init__(parent) self._central_widget = None self.setAttribute(QtCore.Qt.WA_StyledBackground) self.title_label = MLabel(parent=self) self.expand_icon = MLabel(parent=self) self.expand_icon.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self._close_button = MToolButton().icon_only().tiny().svg( "close_line.svg") self._close_button.clicked.connect(self.close) header_lay = QtWidgets.QHBoxLayout() header_lay.addWidget(self.expand_icon) header_lay.addWidget(self.title_label) header_lay.addStretch() header_lay.addWidget(self._close_button) self.header_widget = QtWidgets.QWidget(parent=self) self.header_widget.setAttribute(QtCore.Qt.WA_StyledBackground) self.header_widget.setObjectName("title") self.header_widget.setLayout(header_lay) self.header_widget.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self.header_widget.setCursor(QtCore.Qt.PointingHandCursor) self.title_label.setCursor(QtCore.Qt.PointingHandCursor) self.header_widget.installEventFilter(self) self.title_label.installEventFilter(self) self.content_widget = QtWidgets.QWidget(parent=self) self.content_layout = QtWidgets.QHBoxLayout() self.content_widget.setLayout(self.content_layout) self.main_lay = QtWidgets.QVBoxLayout() self.main_lay.setContentsMargins(0, 0, 0, 0) self.main_lay.setSpacing(0) self.main_lay.addWidget(self.header_widget) self.main_lay.addWidget(self.content_widget) self.setLayout(self.main_lay) self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.setMouseTracking(True) self.set_title(title) self.set_closable(closable) if widget: self.set_content(widget) self.set_expand(expand)
def __init__(self, text="", parent=None): super(MTag, self).__init__(text=text, parent=parent) self._is_pressed = False self._close_button = MToolButton().tiny().svg( "close_line.svg").icon_only() self._close_button.clicked.connect(self.sig_closed) self._close_button.clicked.connect(self.close) self._close_button.setVisible(False) self._main_lay = QHBoxLayout() self._main_lay.setContentsMargins(0, 0, 0, 0) self._main_lay.addStretch() self._main_lay.addWidget(self._close_button) self.setLayout(self._main_lay) self._clickable = False self._border = True self._border_style = QssTemplate(""" MTag{ font-size: @font_size_base@font_unit; padding: @padding_small@unit; color: @text_color; border-radius: @border_radius; border: 1px solid @border_color; background-color: @background_color; } MTag:hover{ color: @hover_color; } """) self._no_border_style = QssTemplate(""" MTag{ font-size: @font_size_base@font_unit; padding: @padding@unit; border-radius: @border_radius; color: @text_color; border: 0 solid @border_color; background-color: @background_color; } MTag:hover{ background-color:@hover_color; } """) self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self._color = None self.set_dayu_color(dayu_theme.secondary_text_color)
def __init__(self, text='New Tag', parent=None): super(MNewTag, self).__init__(parent) self.setAttribute(Qt.WA_StyledBackground) self._add_button = MToolButton().tiny().svg( 'add_line.svg').text_beside_icon() self._add_button.setText(text) self._add_button.clicked.connect(self._slot_show_edit) self._line_edit = MLineEdit().tiny() self._line_edit.returnPressed.connect(self._slot_return_pressed) self._line_edit.setVisible(False) self._main_lay = QGridLayout() self._main_lay.setContentsMargins(3, 3, 3, 3) self._main_lay.addWidget(self._add_button, 0, 0) self._main_lay.addWidget(self._line_edit, 0, 0) self.setLayout(self._main_lay)
def __init__(self, title=None, image=None, size=None, extra=None, type=None, parent=None): super(MCard, self).__init__(parent=parent) self.setAttribute(Qt.WA_StyledBackground) self.setProperty('border', False) size = size or dayu_theme.default_size map_label = { dayu_theme.large: (MLabel.H2Level, 20), dayu_theme.medium: (MLabel.H3Level, 15), dayu_theme.small: (MLabel.H4Level, 10), } self._title_label = MLabel(text=title) self._title_label.set_dayu_level(map_label.get(size)[0]) padding = map_label.get(size)[-1] self._title_layout = QHBoxLayout() self._title_layout.setContentsMargins(padding, padding, padding, padding) if image: self._title_icon = MAvatar() self._title_icon.set_dayu_image(image) self._title_icon.set_dayu_size(size) self._title_layout.addWidget(self._title_icon) self._title_layout.addWidget(self._title_label) self._title_layout.addStretch() if extra: self._extra_button = MToolButton().icon_only().svg('more.svg') self._title_layout.addWidget(self._extra_button) self._content_layout = QVBoxLayout() self._main_lay = QVBoxLayout() self._main_lay.setSpacing(0) self._main_lay.setContentsMargins(1, 1, 1, 1) if title: self._main_lay.addLayout(self._title_layout) self._main_lay.addWidget(MDivider()) self._main_lay.addLayout(self._content_layout) self.setLayout(self._main_lay)
def _init_ui(self): size_lay = QVBoxLayout() sub_lay1 = QHBoxLayout() sub_lay1.addWidget(MToolButton().svg('left_line.svg').icon_only()) sub_lay1.addWidget(MToolButton().svg('right_line.svg').icon_only()) sub_lay1.addWidget(MToolButton().svg('up_line.svg').icon_only()) sub_lay1.addWidget(MToolButton().svg('down_line.svg').icon_only()) sub_lay1.addStretch() size_lay.addLayout(sub_lay1) button2 = MToolButton().svg('detail_line.svg').icon_only() button2.setEnabled(False) button7 = MToolButton().svg('trash_line.svg').icon_only() button7.setCheckable(True) state_lay = QHBoxLayout() state_lay.addWidget(button2) state_lay.addWidget(button7) state_lay.addStretch() button_trash = MToolButton().svg('trash_line.svg').text_beside_icon() button_trash.setText('Delete') button_login = MToolButton().svg('user_line.svg').text_beside_icon() button_login.setText('Login') button_lay = QHBoxLayout() button_lay.addWidget(button_trash) button_lay.addWidget(button_login) sub_lay2 = QHBoxLayout() sub_lay2.addWidget(button2) sub_lay2.addWidget(button7) main_lay = QVBoxLayout() main_lay.addWidget(MDivider('different button_size')) main_lay.addLayout(size_lay) main_lay.addWidget(MDivider('disabled & checkable')) main_lay.addLayout(state_lay) main_lay.addWidget(MDivider('type=normal')) main_lay.addLayout(button_lay) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): self.resize(250, 350) self.button_login = MToolButton().svg( 'user_line.svg').text_beside_icon() self.button_login.setText('Login') self.button_login.clicked.connect(self.onclick) button_lay = QVBoxLayout() button_lay.addWidget(self.button_login) self.tree = QTreeWidget() self.tree.setColumnCount(1) self.tree.setHeaderHidden(1) self.tree.setGeometry(QRect(1, 1, 250, 500)) self.tree.itemClicked.connect(self.testt) new_widget_1 = QTreeWidgetItem(self.tree) new_widget_1.setText(0, u'技能培训') new_widget_2 = QTreeWidgetItem(self.tree) new_widget_2.setText(0, u'企业培训') new_widget_3 = QTreeWidgetItem(self.tree) new_widget_3.setText(0, u'职业技能培训') new_widget_3_1 = QTreeWidgetItem(new_widget_3) new_widget_3_1.setText(0, u'餐饮厨艺') new_widget_3_2 = QTreeWidgetItem(new_widget_3) new_widget_3_2.setText(0, u'家庭服务') new_widget_3_3 = QTreeWidgetItem(new_widget_3) new_widget_3_3.setText(0, u'运输与物流') new_widget_3_3_1 = QTreeWidgetItem(new_widget_3_3) new_widget_3_3_1.setText(0, u'运输与物流第一章') tree_layout = QVBoxLayout() tree_layout.addWidget(self.tree) main_lay = QVBoxLayout() main_lay.addLayout(button_lay) main_lay.addLayout(tree_layout) main_lay.addStretch() self.setLayout(main_lay)
def __init__( self, cover=None, avatar=None, title=None, description=None, extra=False, parent=None, ): super(MMeta, self).__init__(parent) self.setAttribute(QtCore.Qt.WA_StyledBackground) self._cover_label = QtWidgets.QLabel() self._avatar = MAvatar() self._title_label = MLabel().h4() self._description_label = MLabel().secondary() self._description_label.setWordWrap(True) self._description_label.set_elide_mode(QtCore.Qt.ElideRight) self._title_layout = QtWidgets.QHBoxLayout() self._title_layout.addWidget(self._title_label) self._title_layout.addStretch() self._extra_button = MToolButton( parent=self).icon_only().svg("more.svg") self._title_layout.addWidget(self._extra_button) self._extra_button.setVisible(extra) content_lay = QtWidgets.QFormLayout() content_lay.setContentsMargins(5, 5, 5, 5) content_lay.addRow(self._avatar, self._title_layout) content_lay.addRow(self._description_label) self._button_layout = QtWidgets.QHBoxLayout() main_lay = QtWidgets.QVBoxLayout() main_lay.setSpacing(0) main_lay.setContentsMargins(1, 1, 1, 1) main_lay.addWidget(self._cover_label) main_lay.addLayout(content_lay) main_lay.addLayout(self._button_layout) main_lay.addStretch() self.setLayout(main_lay) self._cover_label.setFixedSize(QtCore.QSize(200, 200))
def _init_ui(self): item_list = [ { 'text': 'Overview', 'svg': 'home_line.svg', 'clicked': functools.partial(MMessage.info, u'首页', parent=self) }, { 'text': u'我的', 'svg': 'user_line.svg', 'clicked': functools.partial(MMessage.info, u'编辑账户', parent=self) }, { 'text': u'Notice', 'svg': 'alert_line.svg', 'clicked': functools.partial(MMessage.info, u'查看通知', parent=self) }, ] tool_bar = MMenuTabWidget() tool_bar.tool_bar_insert_widget( MLabel('DaYu').h4().secondary().strong()) tool_bar.tool_bar_append_widget( MBadge.dot( show=True, widget=MToolButton().icon_only().svg('user_fill.svg').large())) self.content_widget = MLabel() for index, data_dict in enumerate(item_list): tool_bar.add_menu(data_dict, index) tool_bar.tool_button_group.set_dayu_checked(0) main_lay = QVBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.addWidget(tool_bar) main_lay.addWidget(self.content_widget) self.setLayout(main_lay)
def error(self): """A a toolset to MLineEdit to store error info with red style""" @Slot() 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() self.setProperty('dayu_type', 'error') self.setReadOnly(True) _suffix_button = MToolButton().icon_only().svg('detail_line.svg') _suffix_button.clicked.connect( functools.partial(_slot_show_detail, self)) self.set_suffix_widget(_suffix_button) self.setPlaceholderText(self.tr('Error information will be here...')) return self
def __init__(self, parent=None): super(MPage, self).__init__(parent) self.register_field('page_size_selected', 25) self.register_field('page_size_list', [{'label': '25 - Fastest', 'value': 25}, {'label': '50 - Fast', 'value': 50}, {'label': '75 - Medium', 'value': 75}, {'label': '100 - Slow', 'value': 100}]) self.register_field('total', 0) self.register_field('current_page', 0) self.register_field('total_page', lambda: utils.get_total_page(self.field('total'), self.field('page_size_selected'))) self.register_field('total_page_text', lambda: str(self.field('total_page'))) self.register_field('display_text', lambda: utils.get_page_display_string(self.field('current_page'), self.field('page_size_selected'), self.field('total'))) self.register_field('can_pre', lambda: self.field('current_page') > 1) self.register_field('can_next', lambda: self.field('current_page') < self.field('total_page')) page_setting_menu = MMenu(parent=self) self._display_label = MLabel() self._display_label.setAlignment(Qt.AlignCenter) self._change_page_size_button = MComboBox().small() self._change_page_size_button.setFixedWidth(110) self._change_page_size_button.set_menu(page_setting_menu) self._change_page_size_button.set_formatter(lambda x: u'{} per page'.format(x)) self._change_page_size_button.sig_value_changed.connect(self._emit_page_changed) self._pre_button = MToolButton().icon_only().svg('left_fill.svg').small() self._pre_button.clicked.connect(functools.partial(self._slot_change_current_page, -1)) self._next_button = MToolButton().small().icon_only().svg('right_fill.svg') self._next_button.clicked.connect(functools.partial(self._slot_change_current_page, 1)) self._current_page_spin_box = MSpinBox() self._current_page_spin_box.setMinimum(1) self._current_page_spin_box.set_dayu_size(dayu_theme.small) self._current_page_spin_box.valueChanged.connect(self._emit_page_changed) self._total_page_label = MLabel() self.bind('page_size_list', page_setting_menu, 'data') self.bind('page_size_selected', page_setting_menu, 'value', signal='sig_value_changed') self.bind('page_size_selected', self._change_page_size_button, 'value', signal='sig_value_changed') self.bind('current_page', self._current_page_spin_box, 'value', signal='valueChanged') self.bind('total_page', self._current_page_spin_box, 'maximum') self.bind('total_page_text', self._total_page_label, 'dayu_text') self.bind('display_text', self._display_label, 'dayu_text') self.bind('can_pre', self._pre_button, 'enabled') self.bind('can_next', self._next_button, 'enabled') main_lay = QHBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(2) main_lay.addStretch() main_lay.addWidget(self._display_label) main_lay.addStretch() main_lay.addWidget(MLabel('|').secondary()) main_lay.addWidget(self._change_page_size_button) main_lay.addWidget(MLabel('|').secondary()) main_lay.addWidget(self._pre_button) main_lay.addWidget(MLabel('Page')) main_lay.addWidget(self._current_page_spin_box) main_lay.addWidget(MLabel('/')) main_lay.addWidget(self._total_page_label) main_lay.addWidget(self._next_button) self.setLayout(main_lay)