我们从Python开源项目中,提取了以下38个代码示例,用于说明如何使用PyQt5.QtWidgets.QDesktopWidget()。
def __init__(self, parent=None): QtWidgets.QFrame.__init__(self, parent) # No title bar, but keep the frame # self.setWindowFlags(QtCore.Qt.CustomizeWindowHint) # Set position of the frame self.screen = QtWidgets.QDesktopWidget().screenGeometry() # Set geometry self.setGeometry(self.screen.width()/8, 50, 1600, 900) self.setMinimumSize(0, 0) # Set Widgets self.sideWindow = SideFrame(self) self.mainWindow = MainFrame(self) # Set Layout self.appLayout = QtWidgets.QHBoxLayout() self.appLayout.addWidget(self.sideWindow, 2) self.appLayout.addWidget(self.mainWindow, 8) # Add layout self.appLayout.setContentsMargins(0, 0, 0, 0) self.appLayout.setSpacing(0) self.setLayout(self.appLayout) self.setWindowTitle("Bayesian Adaptive Trial Simulator") # Close the application
def wpos_set_window(window,name): #print("set") global wlist for i in range(0,len(wlist)): if wlist[i].name==name: shape=QDesktopWidget().screenGeometry() desktop_w=shape.width() desktop_h=shape.height() w=window.width() h=window.height() x=int(wlist[i].x) y=int(wlist[i].y) if (x+w>desktop_w) or x<0: x=desktop_w/2-w/2 #print("Reset with",x) if (y+h>desktop_h) or y<0: y=desktop_h/2-h/2 #print("Reset height",y) window.move(x,y) break
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.dBCommandLineHelper = DBCommandLineHelper() ui_dir_path = os.path.dirname(__file__) ui_file_path = os.path.join(ui_dir_path, 'add_case.ui') uic.loadUi(ui_file_path, self) screen = QDesktopWidget().screenGeometry() self.resize(screen.width() / 5 * 2, screen.height() / 5 * 2) self.search_button = SearchButton() self.tag_names_line_edit = TagLineEdit("tag_names_line_edit", self.search_button) self.tag_names_line_edit_adapter() self.tag_list = None self.result_widget = RunnerTableWidget(self.dBCommandLineHelper.query_case_all(), []) self.result_table_layout.insertWidget(0, self.result_widget) self.message_box = QMessageBox() self.search_button.clicked.connect(self.search_event) self.selectcasebtn.clicked.connect(self.select_event) self.casecancelbtn.clicked.connect(self.close)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.devices_radio_buttons = [] self.data_count = None self.selected_data_number = 0 # init data number, '0' refer to all data self.selected_device_list = [] ui_dir_path = os.path.dirname(__file__) ui_file_path = os.path.join(ui_dir_path, 'add_device.ui') uic.loadUi(ui_file_path, self) screen = QDesktopWidget().screenGeometry() self.resize(screen.width() / 6, screen.height() / 6) self.all_data_selected = True self.line_number_line_edit.hide() self.select_device_btn.clicked.connect(self.select_event) self.cancel_device_btn.clicked.connect(self.close) self.all_radio_btn.clicked.connect(self.data_all_radio_event) self.line_number_radio_btn.clicked.connect(self.data_specified_radio_event) self.message_box = QMessageBox() self.devices_list = []
def rewind(self): if not cfg[CONFIG_BUFFER_STREAM]: QtWidgets.QMessageBox().warning( self, "Warning", "Cannot Rewind. You currently have buffering turned off." ) return if self.rewound is None: self.rewound = QtWidgets.QMainWindow(parent=self) self.rewound.setWindowTitle("Rewound Stream") self.rewound.resize(QtWidgets.QDesktopWidget().availableGeometry(-1).size() * 0.5) self.rewound.frame = RewoundVideoFrame(self.rewound, self.stream.buffer) # Set events: self.rewound.closeEvent = self.close_rewound self.rewound.frame._fullscreen = self.fullscreen_rewound self.rewound.setCentralWidget(self.rewound.frame) self.rewound.show() # Init values self.rewound.is_fullscreen = False # Following functions belong to the rewound window
def __init__(self, parentScoreScene): super().__init__(0, 0, 0, 0) # (x1, y1, x2, y2) self.parentScoreScene = parentScoreScene p = QtGui.QPen() p.setColor(QtGui.QColor("red")) p.setCosmetic(True) self.setPen(p) self.setAcceptHoverEvents(True) api.getCallbacksDatabase().setPlaybackTicks.append(self.setCursorPosition) api.getCallbacksDatabase().tracksChanged.append(self.setLineToWindowHeigth) #for new tracks api.getCallbacksDatabase().updateTempoTrack.append(self.setLineToWindowHeigth) self.setFlags(QtWidgets.QGraphicsItem.ItemIsMovable) self.setAcceptedMouseButtons(QtCore.Qt.LeftButton) self.setZValue(90) #self.parentScoreScene.parentView.verticalScrollBar().valueChanged.connect(self.setLineToWindowHeigth) #self.hide() #self.maxHeight = QtWidgets.QDesktopWidget().geometry().height() #we really hope the screen resolution does not change during the session.
def initUI(self): """ Initialize the MainWindow layout. """ self.setWindowTitle(B3_TITLE) self.setFixedSize(614, 512) ## INIT SUBCOMPONENTS self.setStatusBar(StatusBar(self)) self.setMenuBar(MainMenuBar(self)) self.setCentralWidget(CentralWidget(self)) ## INIT SYSTEM TRAY ICON if b3.getPlatform() != 'linux': self.system_tray = SystemTrayIcon(self) self.system_tray.show() ## MOVE TO CENTER SCREEN screen = QDesktopWidget().screenGeometry() position_x = (screen.width() - self.geometry().width()) / 2 position_y = (screen.height() - self.geometry().height()) / 2 self.move(position_x, position_y) ############################################# EVENTS HANDLERS ######################################################
def center(self): qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) self.resize(1100,200)
def set_view(self, view): if hasattr(self, 'view'): self.view.hide() view.show() self.view = view resolution = QDesktopWidget().screenGeometry() view.move((resolution.width() / 2) - (view.frameSize().width() / 2), (resolution.height() / 2) - (view.frameSize().height() / 2))
def center(self): qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft())
def main(): # assumes unsigned byte datatype and volume dimensions of 256x256x225 volsize = (256, 256, 225) volume = load_raw(os.path.join("data", "head256.raw"), volsize) tff = load_transferfunction(os.path.join("data", "tff.dat")) app = QtWidgets.QApplication([]) window = QGLControllerWidget(volume, volsize, tff) window.move(QtWidgets.QDesktopWidget().rect().center() - window.rect().center()) window.show() app.exec_()
def center(self): """Center the window""" frame = self.frameGeometry() center_point = QtWidgets.QDesktopWidget().availableGeometry().center() frame.moveCenter(center_point) self.move(frame.topLeft()) # EVENTS
def center(window): """Center the given window to desktop Args: window (QMainWindow, QWidget etc.): The window that'll be centered to desktop """ window.move(QDesktopWidget().availableGeometry().center() - window.frameGeometry().center()) #:tag:GUI
def resize_window_to_be_sane(window,x,y): shape=QDesktopWidget().screenGeometry() w=shape.width()*x h=shape.height()*y window.resize(w,h)
def start(self): shape=QDesktopWidget().screenGeometry() w=shape.width() h=shape.height() win_w=self.frameGeometry().width() win_h=self.frameGeometry().height() x=w-win_w y=0 self.move(x,y) self.show()
def move_window(self): shape=QDesktopWidget().screenGeometry() w=shape.width() h=shape.height() win_w=self.frameGeometry().width() win_h=self.frameGeometry().height() x=w-win_w y=50 self.move(x,y)
def refresh_window(self, text): """???????""" # ??????? self.setFixedSize(400, 300) cur = QtGui.QCursor.pos() x = cur.x() + 20 y = cur.y() + 20 # ???????????????? window_h = QDesktopWidget().screenGeometry().height() window_w = QDesktopWidget().screenGeometry().width() if x + 400 > window_h or y + 300 > window_w: x -= 20 + 400 y -= 20 + 300 self.move(x, y) self.setWindowTitle("search for:") self.search_words.setText(text) # ??????? self.voice_play2.hide() self.voice_play1.hide() if len(self.query.word.voices) >= 2: self.voice_label1.setText(self.query.word.voices[1][0]) self.voice_label2.setText(self.query.word.voices[0][0]) print(self.query.word.voices[1][0]) # self.voice_play1.clicked.connect(lambda: self.play_voice(self.query.word.voices[0][1])) # self.voice_play2.clicked.connect(lambda: self.play_voice(self.query.word.voices[1][1])) self.play_voice(self.query.word.voices[1][1]) elif len(self.query.word.voices) == 1: print("lenth 1") self.voice_label1.setText(self.query.word.voices[0][0]) # self.voice_play1.clicked.connect(lambda: self.play_voice(self.query.word.voices[0][1])) self.play_voice(self.query.word.voices[0][1]) else: self.voice_label1.setText("No voices found.") base_info = '' for x in self.query.word.props: base_info += x + self.query.word.props[x] + '\n' self.base_infor_label.setText(base_info)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.show_case_editor_signal.connect(self.show_case_editor, Qt.QueuedConnection) ui_dir_path = os.path.dirname(__file__) ui_file_path = os.path.join(ui_dir_path, 'mainwindow.ui') uic.loadUi(ui_file_path, self) # todo ?????? screen = QDesktopWidget().screenGeometry() self.resize(screen.width() / 2, screen.height() / 2) self.setMinimumSize(700, 350) self.setWindowTitle("uitest") self.move((screen.width() - self.width()) / 2, (screen.height() - self.height()) / 2) # draw centered # Add tab "Case" case_manager_widget = CaseManagerWidget(self.show_case_editor_signal, self.tester) self.tabWidget.addTab(case_manager_widget, "Case") # Add tab "Run" case_run_widget = RunWidget(self.tester) self.tabWidget.addTab(case_run_widget, "Run") # Add tab "Report" case_report_widget = RunnerEventWidget() self.tabWidget.addTab(case_report_widget, "Report") # Add tab "Setting" case_setting_widget = SettingWidget() self.tabWidget.addTab(case_setting_widget, "Setting") self.refresh_case_data_signal.connect(case_manager_widget.refresh) self.message_box = QMessageBox() self.start_rpc_server() self.is_editor_close_cancel = False
def init_ui(self): """ init ui, include: resize window :return: """ screen = QDesktopWidget().screenGeometry() self.resize(screen.width() / 2, screen.height() / 2) self.init_btn_icon() self.id_line_edit.hide() # hide line_edit self.case_name_line_edit.setPlaceholderText("Case Name")
def center(self): """ Description: Just centers the window Arguments: None Returns: Nothing """ qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft())
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self.setWindowFlags(Qt.Window) self.move(QDesktopWidget().availableGeometry().center() - self.frameGeometry().center()) self.label_version.setText(__version__) self.yandex_button.clicked.connect(self.yandex_dialog) self.google_button.clicked.connect(self.google_dialog) self.dropbox_button.clicked.connect(self.dropbox_dialog) self.question_button.clicked.connect(self.about) self.license_button.clicked.connect(self.openUrl)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self.setWindowFlags(Qt.Window) self.move(QDesktopWidget().availableGeometry().center() - self.frameGeometry().center())
def init_display(self, backend_str=None, size=(1024, 768)): from OCC.Display.backend import load_backend, get_qt_modules used_backend = load_backend(backend_str) global display, start_display, app, _, USED_BACKEND if 'qt' in used_backend: from OCC.Display.qtDisplay import qtViewer3d QtCore, QtGui, QtWidgets, QtOpenGL = get_qt_modules() from OCC.Display.qtDisplay import qtViewer3d self.ui.modelTab = qtViewer3d(self) self.setWindowTitle("Osdag Cleat Angle") self.ui.mytabWidget.resize(size[0], size[1]) self.ui.mytabWidget.addTab(self.ui.modelTab, "") self.ui.modelTab.InitDriver() display = self.ui.modelTab._display # background gradient display.set_bg_gradient_color(23, 1, 32, 23, 1, 32) display.display_trihedron() display.View.SetProj(1, 1, 1) def center_on_screen(self): '''Centers the window on the screen.''' resolution = QDesktopWidget().screenGeometry() self.move((resolution.width() / 2) - (self.frameSize().width() / 2), (resolution.height() / 2) - (self.frameSize().height() / 2)) def start_display(): self.ui.modelTab.raise_() return display, start_display
def center(self): """Place the window in the center of the screen.""" qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft())
def center(self): screen = QtWidgets.QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
def __init__(self): super().__init__() self.setWindowTitle(self.tr("Kaptan Desktop")) self.setWindowIcon(QIcon.fromTheme("kaptan")) self.setMinimumSize(850, 600) self.setMaximumSize(950, 720) #x = (QDesktopWidget().screen().width() - self.width())/2 #y = (QDesktopWidget().screen().height() - self.height())/2 #self.move(x, y) self.setPixmap(QWizard.LogoPixmap, QPixmap(":/data/images/logo.svg")) self.setWizardStyle(QWizard.ModernStyle) #self.setButtonText(QWizard.NextButton, self.tr("Next")) #self.button(QWizard.NextButton).setIcon(QIcon.fromTheme("arrow-right")) #self.button(QWizard.NextButton).setLayoutDirection(Qt.RightToLeft) self.setButtonText(QWizard.CancelButton, self.tr("Cancel")) self.button(QWizard.CancelButton).setIcon(QIcon.fromTheme("dialog-cancel")) self.setOption(QWizard.NoCancelButtonOnLastPage, True) self.setOption(QWizard.CancelButtonOnLeft, False) #self.setOption(QWizard.HaveHelpButton, True) self.setButtonText(QWizard.BackButton, self.tr("Back")) self.setOption(QWizard.NoBackButtonOnLastPage, True) self.setOption(QWizard.NoBackButtonOnStartPage, True) self.button(QWizard.BackButton).setIcon(QIcon.fromTheme("arrow-left")) self.setButtonText(QWizard.FinishButton, self.tr("Finish")) self.button(QWizard.FinishButton).setIcon(QIcon.fromTheme("dialog-ok-apply")) self.addPage(WelcomeWidget(self)) self.addPage(MouseWidget(self)) self.addPage(ThemeWidget(self)) self.addPage(MenuWidget(self)) self.addPage(WallpaperWidget(self)) self.addPage(AvatarWidget(self)) #self.addPage(PMWidget()) FIXME self.sumId = self.addPage(SummaryWidget(self)) self.otherId = self.addPage(OtherWidget(self)) self.currentIdChanged.connect(self.optionsAccepted) self.button(QWizard.FinishButton).clicked.connect(self.close)
def openAllGraph(self): self.plot_file_list = self.parent.plot_file[self.root_name] self.graphviewer = QtWidgets.QFrame() self.screen = QtWidgets.QDesktopWidget().screenGeometry() # Set geometry self.graphviewer.setGeometry(self.screen.width()/4, 100, 800, 600) self.graphviewer.setWindowFlags(QtCore.Qt.Popup) self.graphviewer.setObjectName("graphView") self.graphviewer.setStyleSheet("QFrame#graphView{background:#ffffff;border:0.5px solid #fa7064;} QPushButton:hover{background:#6e66cc;border:1px solid #373366;} QToolButton:hover{background:#fa7064;}") # self.graphviewer.setWindowModality(QtCore.Qt.WindowModal) # Layout graph_layout = QtWidgets.QVBoxLayout() # Title graph_title = SubTitleBar(self.graphviewer) graph_title.title_Label.setText(self.root_name) # Separator line hline = QtWidgets.QWidget() hline.setStyleSheet("QWidget{min-height:2px; max-height:2px; background:#399ee5;}") # ComboBox graph_control = QtWidgets.QWidget() graph_control_layout = QtWidgets.QHBoxLayout() self.graph_control_comboBox = QtWidgets.QComboBox() self.graph_control_comboBox.setStyleSheet("QComboBox{font-family:'Segoe UI';font-size: 10pt;border: 1px solid #c5d2d9; border-radius:5px;padding: 5px 10px 5px 10px; color: #66767c;min-width: 250px;} QComboBox:hover{border: 2px solid #2a4d69;border-radius: 5px;height: 30ps;} QComboBox::drop-down {subcontrol-origin: padding; subcontrol-position: top right;width: 40px;border-left-width: 2px;border-left-color: #c5d2d9;border-left-style: solid; border-top-right-radius: 5px; border-bottom-right-radius: 5px;padding: 1px 1px 1px 1px;image: url(:/resources/dropdown_arrow.png);} QComboBox QAbstractItemView {border: 1px solid #c5d2d9; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px;selection-background-color:#4b86b4;outline: solid #2a4d69;font-family: 'Segoe UI';font-size: 10pt;color: #66767c;}") graph_control_layout.insertStretch(0, 4) graph_control_layout.addWidget(self.graph_control_comboBox) graph_control_layout.insertStretch(3, 4) graph_control.setLayout(graph_control_layout) # Main Content self.graph_content = QtWidgets.QStackedWidget() # Add stack for i in range(1, len(self.plot_file_list)): currentName = self.plot_file_list[i].rsplit("/", 1)[1].rsplit(".", 1)[0] self.graph_control_comboBox.addItem(currentName) graph_label = QtWidgets.QLabel() currentGraph = QtGui.QPixmap(self.plot_file_list[i]) graph_label.setPixmap(currentGraph) graph_label.setAlignment(QtCore.Qt.AlignCenter) self.graph_content.addWidget(graph_label) # Add layout graph_layout.addWidget(graph_title, 1) graph_layout.addWidget(hline, 1) graph_layout.addWidget(graph_control, 1) graph_layout.addWidget(self.graph_content, 8) graph_layout.setContentsMargins(5, 10, 5, 10) graph_layout.setAlignment(QtCore.Qt.AlignTop) self.graphviewer.setLayout(graph_layout) self.graph_control_comboBox.currentIndexChanged.connect(self.changeGraph) self.graphviewer.show()
def __init__(self): super().__init__() self.setWindowTitle(self.tr("Kaptan Desktop")) self.setWindowIcon(QIcon.fromTheme("kaptan-icon")) self.setMinimumSize(850, 600) self.setMaximumSize(950, 620) x = (QDesktopWidget().screen().width() - self.width())/2 y = (QDesktopWidget().screen().height() - self.height())/2 self.move(x, y) self.setPixmap(QWizard.LogoPixmap, QPixmap(":/data/images/kaptan.png")) self.setButtonText(QWizard.NextButton, self.tr("Next")) self.button(QWizard.NextButton).setIcon(QIcon.fromTheme("arrow-right")) self.button(QWizard.NextButton).setLayoutDirection(Qt.RightToLeft) self.setButtonText(QWizard.CancelButton, self.tr("Cancel")) self.button(QWizard.CancelButton).setIcon(QIcon.fromTheme("dialog-cancel")) self.setOption(QWizard.NoCancelButtonOnLastPage, True) self.setOption(QWizard.CancelButtonOnLeft, True) self.setButtonText(QWizard.BackButton, self.tr("Back")) self.setOption(QWizard.NoBackButtonOnLastPage, True) self.setOption(QWizard.NoBackButtonOnStartPage, True) self.button(QWizard.BackButton).setIcon(QIcon.fromTheme("arrow-left")) self.setButtonText(QWizard.FinishButton, self.tr("Finish")) self.button(QWizard.FinishButton).setIcon(QIcon.fromTheme("dialog-ok-apply")) self.addPage(WelcomeWidget(self)) self.addPage(MouseWidget(self)) self.addPage(ThemeWidget(self)) self.addPage(MenuWidget(self)) self.addPage(WallpaperWidget(self)) self.addPage(AvatarWidget(self)) #self.addPage(PMWidget()) FIXME self.sumId = self.addPage(SummaryWidget(self)) self.otherId = self.addPage(OtherWidget(self)) self.currentIdChanged.connect(self.optionsAccepted) self.button(QWizard.FinishButton).clicked.connect(self.close)