def center_widget(widget): """ Center QWidget :param widget: widget to center :type widget: QWidget """ screen = QApplication.desktop().screenNumber(QApplication.desktop().cursor().pos()) center = QApplication.desktop().screenGeometry(screen).center() widget.move(center.x() - (widget.width() / 2), center.y() - (widget.height() / 2))
def center_widget(widget): """ Center QWidget :param widget: widget to center :type widget: QWidget """ screen = QApplication.desktop().screenNumber( QApplication.desktop().cursor().pos()) center = QApplication.desktop().screenGeometry(screen).center() widget.move(center.x() - (widget.width() / 2), center.y() - (widget.height() / 2))
def __init__(self, parent=None): super(Result, self).__init__(parent) self.desktop = QApplication.desktop() self.screenRect = self.desktop.screenGeometry() self.h = self.screenRect.height() self.w = self.screenRect.width() self.xr = self.w / 930 self.yr = self.h / 640 self.zr = min(self.xr, self.yr) self.back1_wi = QWidget(self) self.resexit_but = QPushButton(self) self.role1 = QWidget(self.back1_wi) self.role1_head = QLabel(self.role1) self.role1_detail = QWidget(self.role1) self.role1_special = QLabel(self.role1_detail) self.role2 = QWidget(self.back1_wi) self.role2_head = QLabel(self.role2) self.role2_detail = QWidget(self.role2) self.role2_special = QLabel(self.role2_detail) self.role3 = QWidget(self.back1_wi) self.role3_head = QLabel(self.role3) self.role3_detail = QWidget(self.role3) self.role3_special = QLabel(self.role3_detail) self.role4 = QWidget(self.back1_wi) self.role4_head = QLabel(self.role4) self.role4_detail = QWidget(self.role4) self.role4_special = QLabel(self.role4_detail) self.set_ui() with open('result.qss', 'r') as f: self.setStyleSheet(f.read())
def __init__(self, parent=None): super(Home, self).__init__(parent) self.desktop = QApplication.desktop() self.screenRect = self.desktop.screenGeometry() self.h = self.screenRect.height() self.w = self.screenRect.width() self.xr = self.w / 930 self.yr = self.h / 640 self.zr = min(self.xr, self.yr) self.id_p = 0 self.token = '' self.vertical_img = QLabel(self) self.role_data_wi = QWidget(self) self.rankexit_but = QPushButton(self) self.role_header = QLabel(self.role_data_wi) self.role_name = QLabel(self.role_data_wi) self.role_rank = QPushButton(self.role_data_wi) self.ranking = QPushButton(self.role_data_wi) self.role_details = QWidget(self.role_data_wi) self.bigcard_la = QLabel(self.role_details) self.bigcard_wi = QWidget(self.role_details) self.rate_la = QLabel(self.role_details) self.rate_wi = QLabel(self.role_details) self.role_special = QLabel(self.bigcard_wi) self.set_ui() with open('home.qss', 'r') as f: self.setStyleSheet(f.read())
def host_ip_enter(): ip_address, ok = QInputDialog.getText( QApplication.desktop(), "Host's address", "Please, enter the host's " "address:") if ok: return ip_address return
def configure(self): # position if 'position' in self.args: if self.args['position'] == 'center': desktopRect = QApplication.desktop().availableGeometry(self) self.parentWidget().move((desktopRect.width()*0.5) - (self.width() * 0.25), (desktopRect.height()*0.5) - (self.height() * 0.25)) elif (self.args['position'][0] >= 0) & (self.args['position'][1] >= 0): self.parentWidget().move(self.args['position'][0], self.args['position'][1])
def center(self): '''To center the current window in the current display''' desktop = QApplication.desktop() n = desktop.screenNumber(self.cursor().pos()) screen_center = desktop.screenGeometry(n).center() geo_window = self.frameGeometry() geo_window.moveCenter(screen_center) self.move(geo_window.topLeft())
def __init__(self, parent=None, flags=Qt.WindowFlags()): super().__init__(parent=parent, flags=flags) # set x, y, width, height for ui self.WINDOW_MAX_WIDTH = QApplication.desktop().width() self.WINDOW_MAX_HEIGHT = QApplication.desktop().height() self.WINDOW_INIT_HEIGHT = int(self.WINDOW_MAX_HEIGHT / 2) self.WINDOW_INIT_WIDTH = int(self.WINDOW_MAX_WIDTH / 2) self.X = int(self.WINDOW_MAX_WIDTH / 4) self.Y = int(self.WINDOW_MAX_HEIGHT / 4) # set x, y, width, height for box self.BOX_WIDTH = int(self.WINDOW_INIT_WIDTH / 2) self.BOX_HEIGHT = int(self.WINDOW_INIT_HEIGHT / 2) self.BOX_X = int(self.WINDOW_MAX_WIDTH *3 / 8) self.BOX_Y = int(self.WINDOW_MAX_HEIGHT * 3 / 8) # set height for buttons self.BUTTON_HEIGHT = int(self.WINDOW_INIT_HEIGHT / 6) pass
def __init__(self, parent, pixmap): super(ImagePreviewPopup, self).__init__(parent) self.view = EGraphicsView(self) self.setCentralWidget(self.view) self.view.set_image(pixmap) self.setWindowFlags(Qt.Popup|Qt.FramelessWindowHint) self.show() self.move(QApplication.desktop().screen().rect().center() - self.rect().center())
class CONFIG(enumerate): app = QApplication(sys.argv) SCREEN_WIDTH = QApplication.desktop().width() SCREEN_HEIGHT = QApplication.desktop().height() WINDOW_HEIGHT = int(SCREEN_HEIGHT / 2) WINDOW_WIDTH = int(SCREEN_WIDTH / 2) WINDOW_X = int(SCREEN_WIDTH / 4) WINDOW_Y = int(SCREEN_HEIGHT / 4) BOX_WIDTH = int(WINDOW_WIDTH / 2) BOX_HEIGHT = int(WINDOW_HEIGHT / 2) BOX_X = int(SCREEN_WIDTH * 3 / 8) BOX_Y = int(SCREEN_HEIGHT * 3 / 8) pass
def __init__(self, pathtobook, title=None, parent=None, prefs=None): QDialog.__init__(self, parent) self.prefs = prefs or gprefs self.pathtobook = pathtobook self.working = True t = title or os.path.basename(pathtobook) self.book_title = t self.setWindowTitle(_('Edit the ToC in %s') % t) self.setWindowIcon(QIcon(I('highlight_only_on.png'))) l = self.l = QVBoxLayout() self.setLayout(l) self.stacks = s = QStackedWidget(self) l.addWidget(s) self.loading_widget = lw = QWidget(self) s.addWidget(lw) ll = self.ll = QVBoxLayout() lw.setLayout(ll) self.pi = pi = ProgressIndicator() pi.setDisplaySize(QSize(200, 200)) pi.startAnimation() ll.addWidget(pi, alignment=Qt.AlignHCenter | Qt.AlignCenter) la = self.wait_label = QLabel(_('Loading %s, please wait...') % t) la.setWordWrap(True) f = la.font() f.setPointSize(20), la.setFont(f) ll.addWidget(la, alignment=Qt.AlignHCenter | Qt.AlignTop) self.toc_view = TOCView(self, self.prefs) self.toc_view.add_new_item.connect(self.add_new_item) self.toc_view.tocw.history_state_changed.connect( self.update_history_buttons) s.addWidget(self.toc_view) self.item_edit = ItemEdit(self) s.addWidget(self.item_edit) bb = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) l.addWidget(bb) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) self.undo_button = b = bb.addButton(_('&Undo'), bb.ActionRole) b.setToolTip(_('Undo the last action, if any')) b.setIcon(QIcon(I('edit-undo.png'))) b.clicked.connect(self.toc_view.undo) self.explode_done.connect(self.read_toc, type=Qt.QueuedConnection) self.writing_done.connect(self.really_accept, type=Qt.QueuedConnection) r = QApplication.desktop().availableGeometry(self) self.resize(r.width() - 100, r.height() - 100) geom = self.prefs.get('toc_editor_window_geom', None) if geom is not None: QApplication.instance().safe_restore_geometry(self, bytes(geom)) self.stacks.currentChanged.connect(self.update_history_buttons) self.update_history_buttons()
def size_window_raise(): """Вызывается диалоговое окно, предлагающее ввести пользователю размер доски""" size, ok = QInputDialog.getInt(QApplication.desktop(), 'Border size', "Enter a border's size (since 4 to 12):", value=10, min=4, max=12, step=1) if ok: return size return
def popup(self, select_first=True): if self.disable_popup: return p = self m = p.model() widget = self.completer_widget() if widget is None: return screen = QApplication.desktop().availableGeometry(widget) h = (p.sizeHintForRow(0) * min(self.max_visible_items, m.rowCount()) + 3) + 3 hsb = p.horizontalScrollBar() if hsb and hsb.isVisible(): h += hsb.sizeHint().height() rh = widget.height() pos = widget.mapToGlobal(QPoint(0, widget.height() - 2)) w = min(widget.width(), screen.width()) if (pos.x() + w) > (screen.x() + screen.width()): pos.setX(screen.x() + screen.width() - w) if pos.x() < screen.x(): pos.setX(screen.x()) top = pos.y() - rh - screen.top() + 2 bottom = screen.bottom() - pos.y() h = max(h, p.minimumHeight()) if h > bottom: h = min(max(top, bottom), h) if top > bottom: pos.setY(pos.y() - h - rh + 2) p.setGeometry(pos.x(), pos.y(), w, h) if ( tweaks["preselect_first_completion"] and select_first and not self.currentIndex().isValid() and self.model().rowCount() > 0 ): self.setCurrentIndex(self.model().index(0)) if not p.isVisible(): if isosx and get_osx_version() >= (10, 9, 0): # On mavericks the popup menu seems to use a font smaller than # the widgets font, see for example: # https://bugs.launchpad.net/bugs/1243761 fp = QFontInfo(widget.font()) f = QFont() f.setPixelSize(fp.pixelSize()) self.setFont(f) p.show()
def popup(self, select_first=True): if self.disable_popup: return p = self m = p.model() widget = self.completer_widget() if widget is None: return screen = QApplication.desktop().availableGeometry(widget) h = (p.sizeHintForRow(0) * min(self.max_visible_items, m.rowCount()) + 3) + 3 hsb = p.horizontalScrollBar() if hsb and hsb.isVisible(): h += hsb.sizeHint().height() rh = widget.height() pos = widget.mapToGlobal(QPoint(0, widget.height() - 2)) w = min(widget.width(), screen.width()) if (pos.x() + w) > (screen.x() + screen.width()): pos.setX(screen.x() + screen.width() - w) if pos.x() < screen.x(): pos.setX(screen.x()) top = pos.y() - rh - screen.top() + 2 bottom = screen.bottom() - pos.y() h = max(h, p.minimumHeight()) if h > bottom: h = min(max(top, bottom), h) if top > bottom: pos.setY(pos.y() - h - rh + 2) p.setGeometry(pos.x(), pos.y(), w, h) if (tweaks['preselect_first_completion'] and select_first and not self.currentIndex().isValid() and self.model().rowCount() > 0): self.setCurrentIndex(self.model().index(0)) if not p.isVisible(): if isosx and get_osx_version() >= (10, 9, 0): # On mavericks the popup menu seems to use a font smaller than # the widgets font, see for example: # https://bugs.launchpad.net/bugs/1243761 fp = QFontInfo(widget.font()) f = QFont() f.setPixelSize(fp.pixelSize()) self.setFont(f) p.show()
def __init__(self, parent=None): super(Main, self).__init__(parent) self.desktop = QApplication.desktop() self.screenRect = self.desktop.screenGeometry() self.h = self.screenRect.height() self.w = self.screenRect.width() self.xr = self.w / 930 self.yr = self.h / 640 self.zr = min(self.xr, self.yr) self.resize(self.w, self.h) palette = QPalette() palette.setBrush( QPalette.Background, QBrush(QPixmap("./resource/image/back.jpg").scaled(self.size()))) self.setPalette(palette)
def __init__(self, parent=None): super(Search, self).__init__(parent) self.desktop = QApplication.desktop() self.screenRect = self.desktop.screenGeometry() self.h = self.screenRect.height() self.w = self.screenRect.width() self.xr = self.w / 930 self.yr = self.h / 640 self.zr = min(self.xr, self.yr) self.token = '' self.head = QLabel(self) self.search = QLineEdit(self) self.butt = QPushButton(self) self.but = QPushButton(self) self.set_ui()
def __init__(self, parent, project, name="New ScreenshotGroup", callback=None): super(CreateScreenshotGroupPopup, self).__init__(parent) self.setWindowFlags(Qt.Popup | Qt.FramelessWindowHint) self.line_name = QLineEdit(self) self.line_name.setText(name) self.project = project self.callback = callback self.btn_ok = QPushButton("Create Screenshot Group", self) self.btn_ok.clicked.connect(self.on_ok) self.setCentralWidget(QWidget(self)) self.centralWidget().setLayout(QHBoxLayout(self)) self.centralWidget().layout().addWidget(self.line_name) self.centralWidget().layout().addWidget(self.btn_ok) self.setMinimumWidth(300) self.show() self.move(QApplication.desktop().screen().rect().center() - self.rect().center())
def __init__(self, parent, on_finished, pos = None, size = QSize(500,150), text = ""): super(TextEditPopup, self).__init__(parent) self.view = QPlainTextEdit(self) self.view.setPlainText(text) self.setCentralWidget(self.view) self.setWindowFlags(Qt.Popup|Qt.FramelessWindowHint) self.onFinished.connect(on_finished) self.show() if pos is None: self.move(QApplication.desktop().screen().rect().center() - self.rect().center()) else: self.move(pos) self.resize(size) self.view.setFocus()
def set_UI(self): self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setFrameShape(QFrame.NoFrame) self.setFixedHeight(100) self.setFixedWidth(800) self.setAttribute(Qt.WA_TranslucentBackground) desktop = QApplication.desktop() desktop_rect = desktop.screenGeometry() self.move((desktop_rect.width() - 800) // 2, 0) self.set_labels() self.set_layout() self.hide() with open('QSS\\lyric_panel.qss', 'r') as file_obj: self.setStyleSheet(file_obj.read())
def popup(self, select_first=True): if self.disable_popup: return p = self m = p.model() widget = self.parent() if widget is None: return screen = QApplication.desktop().availableGeometry(widget) h = (p.sizeHintForRow(0) * min(self.max_visible_items, m.rowCount()) + 3) + 3 hsb = p.horizontalScrollBar() if hsb and hsb.isVisible(): h += hsb.sizeHint().height() rh = widget.height() pos = widget.mapToGlobal(QPoint(0, widget.height() - 2)) w = min(widget.width(), screen.width()) if (pos.x() + w) > (screen.x() + screen.width()): pos.setX(screen.x() + screen.width() - w) if pos.x() < screen.x(): pos.setX(screen.x()) top = pos.y() - rh - screen.top() + 2 bottom = screen.bottom() - pos.y() h = max(h, p.minimumHeight()) if h > bottom: h = min(max(top, bottom), h) if top > bottom: pos.setY(pos.y() - h - rh + 2) p.setGeometry(pos.x(), pos.y(), w, h) if (tweaks['preselect_first_completion'] and select_first and not self.currentIndex().isValid() and self.model().rowCount() > 0): self.setCurrentIndex(self.model().index(0)) if not p.isVisible(): p.show()
def __init__(self, parent=None): super(Register, self).__init__(parent) self.desktop = QApplication.desktop() self.screenRect = self.desktop.screenGeometry() self.h = self.screenRect.height() self.w = self.screenRect.width() self.xr = self.w / 930 self.yr = self.h / 640 self.zr = min(self.xr, self.yr) self.top_wi = QWidget(self) self.logo_la = QLabel(self.top_wi) self.ind_wi = QWidget(self) self.register_but = QPushButton(self.ind_wi) self.imp_la = QLabel(self.ind_wi) self.account_le = QLineEdit(self.ind_wi) self.psw_le = QLineEdit(self.ind_wi) self.name_le = QLineEdit(self.ind_wi) self.set_ui() with open('index.qss', 'r') as f: self.setStyleSheet(f.read())
def _setup_ui(self): log.info('create widgets') """創建介面物件""" from .custom_widgets import LayoutWidget, make_layout from .header import Header from .body import Body from .footer import Footer from .sidebar import Sidebar from .dialog import SecondScreenView self.setStyleSheet(self._default) log.info('finish widgets') # 尺寸 self.setGeometry(100, 80, 1600, 1100) # 版面 widget = LayoutWidget(horizon=False) hlayout = make_layout() vlayout = make_layout(horizon=False) vlayout.addLayout(Body()) vlayout.addWidget(Footer()) hlayout.addWidget(Sidebar()) hlayout.addLayout(vlayout) # 設定 widget.addWidget(Header()) widget.addLayout(hlayout) self.setCentralWidget(widget) # 置中 self.layout().invalidate() self.layout().activate() center = self.rect().center() dcenter = QApplication.desktop().screenGeometry().center() self.move(dcenter - center) # 全螢幕預覽 self._second_screen = SecondScreenView()
def __init__(self, parent=None): super(SingleRank, self).__init__(parent) self.desktop = QApplication.desktop() self.screenRect = self.desktop.screenGeometry() self.h = self.screenRect.height() self.w = self.screenRect.width() self.xr = self.w / 930 self.yr = self.h / 640 self.zr = min(self.xr, self.yr) self.inlist = {} self.back2_wi = QWidget(self) self.rankexit_but = QPushButton(self) self.header1 = QLabel(self.back2_wi) self.comeback_but = QPushButton(self.back2_wi) self.next_but = QPushButton(self.back2_wi) self.table = QWidget(self.back2_wi) self.tablein = QGridLayout() self.headers = ['对局id', '分数', '时间', '详情'] self.set_ui() with open('rank.qss', 'r') as f: self.setStyleSheet(f.read())
def __init__(self, parent=None): super(MainIndex, self).__init__(parent) self.desktop = QApplication.desktop() self.screenRect = self.desktop.screenGeometry() self.h = self.screenRect.height() self.w = self.screenRect.width() self.xr = self.w / 930 self.yr = self.h / 640 self.zr = min(self.xr, self.yr) self.token = '' self.top_wi = QWidget(self) self.logo_la = QLabel(self.top_wi) self.manual_but = QPushButton(self) # self.manual_tex = QLabel(self) self.auto_but = QPushButton(self) # self.auto_tex = QLabel(self) self.home_but = QPushButton(self) # self.home_tex = QLabel(self) self.loading = QLabel(self) self.gif = QMovie('./resource/image/load.gif') self.set_ui() with open('mainindex.qss', 'r') as f: self.setStyleSheet(f.read())
def sizeHint(self): rect = QApplication.desktop().screenGeometry(self) return rect.size() * 0.9
def get_screen_dpi(): d = QApplication.desktop() return (d.logicalDpiX(), d.logicalDpiY())
def setupUi(self): self.setObjectName("top_win") # self.resize(551, 261) self.setStyleSheet(self.qss) self.gridLayoutWidget = QWidget(self) # logging.warning('gridLayoutWidget sheet {}'.format( # self.gridLayoutWidget.styleSheet())) self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 511, 221)) self.gridLayoutWidget.setObjectName("gridLayoutWidget") self.gridLayout = QGridLayout(self.gridLayoutWidget) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setObjectName("gridLayout") self.lab_date = QLabel(self.gridLayoutWidget) self.lab_date.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) self.lab_date.setObjectName("lab_date") self.gridLayout.addWidget(self.lab_date, 0, 0, 1, 1) self.verticalLayout = QVBoxLayout() self.lab_time = QLabel(self.gridLayoutWidget) self.lab_time.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) self.lab_time.setFixedHeight(100) self.lab_time.setObjectName("lab_time") self.verticalLayout.addWidget(self.lab_time) self.lab_title = QLabel(self.gridLayoutWidget) self.lab_title.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) self.lab_title.setObjectName("lab_title") self.lab_title.setText('Yang wish list - Ho to do list') self.verticalLayout.addWidget(self.lab_title) # listWidget qss = """ TransparentListWidget{ background:transparent; selection-background-color:transparent; } """ self.listWidget_todo = TransparentFactory().get_widget('listWidget', qss=qss) for mission_id, mission_config in TIME_MISSION.missions.items(): if mission_config['is_action']: self.item = TodoListWidgetItem(parent=self.listWidget_todo) self.listWidget_todo.setItemWidget( self.item, self.item.setupUi( mission_name=mission_config['mission_name'])) self.verticalLayout.addWidget(self.listWidget_todo) self.gridLayout.addLayout(self.verticalLayout, 1, 1, 2, 2) self.horizontalLayout = QHBoxLayout() self.btn_pass = TransparentButton(self.gridLayoutWidget) self.btn_pass.setObjectName("btn_pass") self.btn_pass.setFixedWidth(60) self.btn_later = TransparentButton(self.gridLayoutWidget) self.btn_later.setObjectName("btn_later") self.btn_later.setMinimumWidth(120) self.horizontalLayout.addWidget(self.btn_pass) self.horizontalLayout.addWidget(self.btn_later) self.gridLayout.addLayout(self.horizontalLayout, 3, 3, 1, 1) self.retranslateUi() QtCore.QMetaObject.connectSlotsByName(self) width = QApplication.desktop().availableGeometry().width() height = QApplication.desktop().availableGeometry().height() if IS_FULL: screen_rate = 1 else: screen_rate = 0.8 self.resize(int(width * screen_rate), int(height * screen_rate)) self.gridLayoutWidget.setGeometry( QtCore.QRect(20, 20, int(width * screen_rate) - 40, int(height * screen_rate) - 40))
from PyQt5.Qt import QApplication from PyQt5.QtWidgets import QMessageBox from ui.main_window import MainWindow from core.session import Session from core.util import Utility import sys import logging CONFIG_FILE_PATH = "config/config.conf" if __name__ == '__main__': app = QApplication(sys.argv) logging.basicConfig(level=logging.INFO) try: session = Session(CONFIG_FILE_PATH) except ValueError as e: QMessageBox.warning(None, "Error", "Error parsing config file...") sys.exit(1) except (OSError, IOError) as e: QMessageBox.warning(None, "Error", "Couldn't open config file") sys.exit(1) main_window = MainWindow(app.desktop(), session) main_window.show() sys.exit(app.exec_())