我们从Python开源项目中,提取了以下38个代码示例,用于说明如何使用PySide.QtGui.QDialog()。
def setupWin(self): super(self.__class__,self).setupWin() self.setGeometry(500, 300, 250, 110) # self.resize(250,250) #------------------------------ # template list: for frameless or always on top option #------------------------------ # - template : keep ui always on top of all; # While in Maya, dont set Maya as its parent ''' self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) ''' # - template: hide ui border frame; # While in Maya, use QDialog instead, as QMainWindow will make it disappear ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint) ''' # - template: best solution for Maya QDialog without parent, for always on-Top frameless ui ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) ''' # - template: for transparent and non-regular shape ui # note: use it if you set main ui to transparent, and want to use alpha png as irregular shape window # note: black color better than white for better look of semi trans edge, like pre-mutiply ''' self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setStyleSheet("background-color: rgba(0, 0, 0,0);") '''
def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle(u'Add new category') # self.categoryName = QtGui.QLineEdit('') self.categoryName.setStyleSheet('background-color:#FFF;') self.categoryDescription = QtGui.QTextEdit('') # buttons buttons = QtGui.QDialogButtonBox() buttons.setOrientation(QtCore.Qt.Vertical) buttons.addButton("Cancel", QtGui.QDialogButtonBox.RejectRole) buttons.addButton("Add", QtGui.QDialogButtonBox.AcceptRole) self.connect(buttons, QtCore.SIGNAL("accepted()"), self, QtCore.SLOT("accept()")) self.connect(buttons, QtCore.SIGNAL("rejected()"), self, QtCore.SLOT("reject()")) # lay = QtGui.QGridLayout(self) lay.addWidget(QtGui.QLabel(u'Name'), 0, 0, 1, 1) lay.addWidget(self.categoryName, 0, 1, 1, 1) lay.addWidget(QtGui.QLabel(u'Desctiption'), 1, 0, 1, 1, QtCore.Qt.AlignTop) lay.addWidget(self.categoryDescription, 1, 1, 1, 1) lay.addWidget(buttons, 0, 2, 2, 1, QtCore.Qt.AlignCenter) lay.setRowStretch(1, 10)
def __init__(self, model, paths, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle(u'Choose model') # self.modelsList = QtGui.QListWidget() for i in paths: self.modelsList.addItem(i) self.modelsList.setCurrentRow(0) # buttons = QtGui.QDialogButtonBox() buttons.setOrientation(QtCore.Qt.Vertical) buttons.addButton("Cancel", QtGui.QDialogButtonBox.RejectRole) buttons.addButton("Choose", QtGui.QDialogButtonBox.AcceptRole) self.connect(buttons, QtCore.SIGNAL("accepted()"), self, QtCore.SLOT("accept()")) self.connect(buttons, QtCore.SIGNAL("rejected()"), self, QtCore.SLOT("reject()")) # lay = QtGui.QGridLayout(self) lay.addWidget(QtGui.QLabel(u"Choose one of available models for part"), 0, 0, 1, 1) lay.addWidget(QtGui.QLabel(u"<div style='font-weight:bold;'>{0}</div>".format(model)), 1, 0, 1, 1, QtCore.Qt.AlignHCenter) lay.addWidget(self.modelsList, 2, 0, 1, 1) lay.addWidget(buttons, 2, 1, 1, 1)
def setupWin(self): self.setWindowTitle("TMP_UniversalToolUI_TND" + " - v" + self.version) self.setGeometry(300, 300, 800, 600) # win icon setup path = os.path.join(os.path.dirname(self.location),'icons','TMP_UniversalToolUI_TND.png') self.setWindowIcon(QtGui.QIcon(path)) # initial win drag position self.drag_position=QtGui.QCursor.pos() #self.resize(250,250) # - for frameless or always on top option #self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # it will keep ui always on top of desktop, but to set this in Maya, dont set Maya as its parent #self.setWindowFlags(QtCore.Qt.FramelessWindowHint) # it will hide ui border frame, but in Maya, use QDialog instead as QMainWindow will disappear #self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) # best for Maya case with QDialog without parent, for always top frameless ui # - for transparent and non-regular shape ui #self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # use it if you set main ui to transparent and want to use alpha png as irregular shape window #self.setStyleSheet("background-color: rgba(0, 0, 0,0);") # black color better white color for get better look of semi trans edge, like pre-mutiply
def setupWin(self): self.setWindowTitle("UITranslator" + " - v" + self.version) self.setGeometry(300, 300, 300, 300) # win icon setup path = os.path.join(os.path.dirname(self.location),'icons','UITranslator.png') self.setWindowIcon(QtGui.QIcon(path)) # initial win drag position self.drag_position=QtGui.QCursor.pos() #self.resize(250,250) # - for frameless or always on top option #self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # it will keep ui always on top of desktop, but to set this in Maya, dont set Maya as its parent #self.setWindowFlags(QtCore.Qt.FramelessWindowHint) # it will hide ui border frame, but in Maya, use QDialog instead as QMainWindow will disappear #self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) # best for Maya case with QDialog without parent, for always top frameless ui # - for transparent and non-regular shape ui #self.setAttribute(QtCore.Qt.WA_TranslucentBackground) # use it if you set main ui to transparent and want to use alpha png as irregular shape window #self.setStyleSheet("background-color: rgba(0, 0, 0,0);") # black color better white color for get better look of semi trans edge, like pre-mutiply
def __init__(self, plot, parent=None): QtGui.QDialog.__init__(self, parent) loadUi(get_resource('transect.ui'), baseinstance=self) pxmap = self.style().standardPixmap self.closeButton.setIcon( pxmap(QtGui.QStyle.SP_DialogCloseButton)) self.createButton.setIcon( pxmap(QtGui.QStyle.SP_ArrowUp)) self.removeButton.setIcon( pxmap(QtGui.QStyle.SP_DialogDiscardButton)) self.plot = plot self.poly_line = None self.trans_plot = pg.PlotDataItem( antialias=True, fillLevel=0., fillBrush=pg.mkBrush(0, 127, 0, 150)) self.plt_wdgt = pg.PlotWidget() self.plt_wdgt.setLabels( bottom={'Distance', 'm'}, left='Displacement [m]') self.plt_wdgt.showGrid(True, True, alpha=.5) self.plt_wdgt.enableAutoRange() self.plt_wdgt.addItem(self.trans_plot) self.layoutPlot.addWidget(self.plt_wdgt) self.plot.image.sigImageChanged.connect(self.updateTransPlot) self.createButton.released.connect(self.addPolyLine) self.removeButton.released.connect(self.removePolyLine) parent.model.sigConfigChanged.connect(self.close)
def __init__(self, model, parent=None): QtGui.QDialog.__init__(self, parent) loadUi(get_resource('covariance_matrix.ui'), baseinstance=self) self.closeButton.setIcon( self.style().standardPixmap(QtGui.QStyle.SP_DialogCloseButton)) self.weight_matrix = self.MatrixPlot(model) self.dockarea = dockarea.DockArea(self) self.dockarea.addDock( dockarea.Dock( 'Covariance.weight_matrix_focal', widget=self.weight_matrix, size=(4, 4), autoOrientation=False,), position='left') self.horizontalLayoutPlot.addWidget(self.dockarea)
def __init__(self): QtGui.QDialog.__init__(self) self.setupUi()
def __init__(self, servers_json_path): QtGui.QDialog.__init__(self) self.downloaded = False self.setupUi() self.servers_json_path = servers_json_path self.servers_download_function()
def _define_qt_base(self): """ This will be called at initialisation time and will allow a user to control various aspects of how QT is being used by Toolkit. The method should return a dictionary with a number of specific keys, outlined below. * qt_core - the QtCore module to use * qt_gui - the QtGui module to use * dialog_base - base class for to use for Toolkit's dialog factory :returns: dict """ base = {} from PySide import QtCore, QtGui base["qt_core"] = QtCore base["qt_gui"] = QtGui base["dialog_base"] = QtGui.QDialog # tell QT to handle text strings as utf-8 by default utf8 = QtCore.QTextCodec.codecForName("utf-8") QtCore.QTextCodec.setCodecForCStrings(utf8) self._override_qmessagebox() return base
def __init__(self, categoryID, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle(u'Update category') self.categoryID = categoryID categoryData = readCategories()[self.categoryID] # self.categoryName = QtGui.QLineEdit('') self.categoryName.setStyleSheet('background-color:#FFF;') self.categoryName.setText(categoryData[0]) self.categoryDescription = QtGui.QTextEdit('') self.categoryDescription.setText(categoryData[1]) # buttons buttons = QtGui.QDialogButtonBox() buttons.setOrientation(QtCore.Qt.Vertical) buttons.addButton("Cancel", QtGui.QDialogButtonBox.RejectRole) buttons.addButton("Update", QtGui.QDialogButtonBox.AcceptRole) self.connect(buttons, QtCore.SIGNAL("accepted()"), self, QtCore.SLOT("accept()")) self.connect(buttons, QtCore.SIGNAL("rejected()"), self, QtCore.SLOT("reject()")) # lay = QtGui.QGridLayout(self) lay.addWidget(QtGui.QLabel(u'Name'), 0, 0, 1, 1) lay.addWidget(self.categoryName, 0, 1, 1, 1) lay.addWidget(QtGui.QLabel(u'Desctiption'), 1, 0, 1, 1, QtCore.Qt.AlignTop) lay.addWidget(self.categoryDescription, 1, 1, 1, 1) lay.addWidget(buttons, 0, 2, 2, 1, QtCore.Qt.AlignCenter) lay.setRowStretch(1, 10)
def defConstraintAreaF(self): ''' create constraint are dialog ''' dial = QtGui.QDialog() dial.setWindowTitle("Create constraint area") # areas list lista = QtGui.QListWidget() for i, j in PCBconstraintAreas.items(): a = QtGui.QListWidgetItem(j[0]) a.setData(QtCore.Qt.UserRole, i) lista.addItem(a) lista.sortItems() ########## # przyciski buttons = QtGui.QDialogButtonBox() buttons.setOrientation(QtCore.Qt.Vertical) buttons.addButton("Cancel", QtGui.QDialogButtonBox.RejectRole) buttons.addButton("Create", QtGui.QDialogButtonBox.AcceptRole) dial.connect(buttons, QtCore.SIGNAL("accepted()"), dial, QtCore.SLOT("accept()")) dial.connect(buttons, QtCore.SIGNAL("rejected()"), dial, QtCore.SLOT("reject()")) #### lay = QtGui.QGridLayout() lay.addWidget(lista, 0, 0, 1, 1) lay.addWidget(buttons, 0, 1, 1, 1) dial.setLayout(lay) if dial.exec_(): self.constraintAreaF(str(lista.currentItem().data(QtCore.Qt.UserRole)))
def __init__(self): QtGui.QDialog.__init__(self) self.setupUi(self) # Set up the user interface from Designer. self.show()
def setupUI(self): #------------------------------ # main_layout auto creation for holding all the UI elements #------------------------------ main_layout = None if isinstance(self, QtWidgets.QMainWindow): main_widget = QtWidgets.QWidget() self.setCentralWidget(main_widget) main_layout = self.quickLayout('vbox', 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) else: # main_layout for QDialog main_layout = self.quickLayout('vbox', 'main_layout') self.setLayout(main_layout) #------------------------------ # user ui creation part #------------------------------ # + template: qui version since universal tool template v7 # - no extra variable name, all text based creation and reference self.qui('dict_table | source_txtEdit | result_txtEdit','info_split;v') self.qui('filePath_input | fileLoad_btn;Load | fileLang_choice | fileExport_btn;Export', 'fileBtn_layout;hbox') self.qui('info_split | process_btn;Process and Update Memory From UI | fileBtn_layout', 'main_layout') self.uiList["source_txtEdit"].setWrap(0) self.uiList["result_txtEdit"].setWrap(0) #------------- end ui creation -------------------- for name,each in self.uiList.items(): if isinstance(each, QtWidgets.QLayout) and name!='main_layout' and not name.endswith('_grp_layout'): each.setContentsMargins(0,0,0,0) # clear extra margin some nested layout #self.quickInfo('Ready')
def setupUI(self, layout='grid'): #------------------------------ # main_layout auto creation for holding all the UI elements #------------------------------ main_layout = None if isinstance(self, QtWidgets.QMainWindow): main_widget = QtWidgets.QWidget() self.setCentralWidget(main_widget) main_layout = self.quickLayout(layout, 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) else: # main_layout for QDialog main_layout = self.quickLayout(layout, 'main_layout') self.setLayout(main_layout)
def __init__(self, parent=None, mode=0): QtGui.QMainWindow.__init__(self, parent) #QtGui.QDialog.__init__(self, parent) self.version="0.1" self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.fileType='.TMP_UniversalToolUI_TND_EXT' # mode: example for receive extra user input as parameter self.mode = 0 if mode in [0,1]: self.mode = mode # mode validator self.location = "" if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(__file__) # location: ref: sys.modules[__name__].__file__ #~~~~~~~~~~~~~~~~~~ # initial data #~~~~~~~~~~~~~~~~~~ self.memoData['data']=[] self.setupStyle() self.setupMenu() # only if you use QMainWindows Class self.setupWin() self.setupUI() self.Establish_Connections() self.loadData() self.loadLang()
def __init__(self, parent=None, mode=0): QtGui.QMainWindow.__init__(self, parent) #QtGui.QDialog.__init__(self, parent) self.version="1.0" self.uiList={} # for ui obj storage self.memoData = {} # key based variable data storage self.fileType='.UITranslator_EXT' # mode: example for receive extra user input as parameter self.mode = 0 if mode in [0,1]: self.mode = mode # mode validator self.location = "" if getattr(sys, 'frozen', False): # frozen - cx_freeze self.location = sys.executable else: # unfrozen self.location = os.path.realpath(__file__) # location: ref: sys.modules[__name__].__file__ self.setupStyle() self.setupMenu() # only if you use QMainWindows Class self.setupWin() self.setupUI() self.Establish_Connections() self.loadData() self.loadLang()
def setupUI(self): #============================== # main_layout for QMainWindow main_widget = QtGui.QWidget() self.setCentralWidget(main_widget) main_layout = self.quickLayout('vbox') # grid for auto fill window size main_widget.setLayout(main_layout) ''' # main_layout for QDialog main_layout = self.quickLayout('vbox') self.setLayout(main_layout) ''' #------------------------------ # ui element creation part info_split = self.quickSplitUI( "info_split", self.quickUI(["dict_table;QTableWidget","source_txtEdit;LNTextEdit","result_txtEdit;LNTextEdit"]), "v" ) fileBtn_layout = self.quickUI(["filePath_input;QLineEdit", "fileLoad_btn;QPushButton;Load", "fileLang_choice;QComboBox", "fileExport_btn;QPushButton;Export"],"fileBtn_QHBoxLayout") self.quickUI( [info_split, "process_btn;QPushButton;Process and Update Memory From UI", fileBtn_layout], main_layout) self.uiList["source_txtEdit"].setWrap(0) self.uiList["result_txtEdit"].setWrap(0) ''' self.uiList['secret_btn'] = QtGui.QPushButton(self) # invisible but functional button self.uiList['secret_btn'].setText("") self.uiList['secret_btn'].setGeometry(0, 0, 50, 20) self.uiList['secret_btn'].setStyleSheet("QPushButton{background-color: rgba(0, 0, 0,0);} QPushButton:pressed{background-color: rgba(0, 0, 0,0); border: 0px;} QPushButton:hover{background-color: rgba(0, 0, 0,0); border: 0px;}") #:hover:pressed:focus:hover:disabled '''
def setupWin(self): self.setWindowTitle(self.name + " - v" + self.version + " - host: " + hostMode) self.setWindowIcon(self.icon) # initial win drag position self.drag_position=QtGui.QCursor.pos() self.setGeometry(500, 300, 250, 110) # self.resize(250,250) #------------------------------ # template list: for frameless or always on top option #------------------------------ # - template : keep ui always on top of all; # While in Maya, dont set Maya as its parent ''' self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) ''' # - template: hide ui border frame; # While in Maya, use QDialog instead, as QMainWindow will make it disappear ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint) ''' # - template: best solution for Maya QDialog without parent, for always on-Top frameless ui ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) ''' # - template: for transparent and non-regular shape ui # note: use it if you set main ui to transparent, and want to use alpha png as irregular shape window # note: black color better than white for better look of semi trans edge, like pre-mutiply ''' self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setStyleSheet("background-color: rgba(0, 0, 0,0);") ''' ############################################# # customized SUPER quick ui function for speed up programming #############################################
def setupUI(self): #------------------------------ # main_layout auto creation for holding all the UI elements #------------------------------ main_layout = None if isinstance(self, QtWidgets.QMainWindow): main_widget = QtWidgets.QWidget() self.setCentralWidget(main_widget) main_layout = self.quickLayout('vbox', 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) else: # main_layout for QDialog main_layout = self.quickLayout('vbox', 'main_layout') self.setLayout(main_layout)
def tm_make_preview_ui(self): self.makePreviewDialog = QtGui.QDialog(self) self.makePreviewDialog.setModal(True) #self.makePreviewDialog.resize(300, 300) self.makePreviewDialog.setWindowTitle(('Make Preview: /// ' + self.current_task['asset'])) # add widgets v_layout = QtGui.QVBoxLayout() # -- image Label self.makePreviewDialog.imageLabel = QtGui.QLabel() self.makePreviewDialog.imageLabel.setFixedSize(300,300) v_layout.addWidget(self.makePreviewDialog.imageLabel) # -- button h__layout = QtGui.QHBoxLayout() button_frame = QtGui.QFrame(parent = self.makePreviewDialog) cansel_button = QtGui.QPushButton('Cansel', parent = button_frame) h__layout.addWidget(cansel_button) paste_button = QtGui.QPushButton('Paste', parent = button_frame) h__layout.addWidget(paste_button) save_button = QtGui.QPushButton('Save', parent = button_frame) h__layout.addWidget(save_button) button_frame.setLayout(h__layout) v_layout.addWidget(button_frame) self.makePreviewDialog.setLayout(v_layout) # connect buttons cansel_button.clicked.connect(partial(self.close_window, self.makePreviewDialog)) paste_button.clicked.connect(partial(self.tm_paste_image_from_clipboard, self.makePreviewDialog.imageLabel)) save_button.clicked.connect(partial(self.tm_save_preview_image_action, self.makePreviewDialog)) # -- load img to label img_path = os.path.join(self.db_chat.preview_img_path, (self.current_task['asset'] + '.png')) if not os.path.exists(img_path): self.makePreviewDialog.imageLabel.setText('No Image') else: image = QtGui.QImage(img_path) self.makePreviewDialog.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image)) self.makePreviewDialog.show()
def __init__(self, sandbox, *args, **kwargs): QtGui.QDialog.__init__(self, *args, **kwargs) loadUi(get_resource('dialog_extent.ui'), self) self.setSizeGripEnabled(False) self.move( self.parent().window().mapToGlobal( self.parent().window().rect().center()) - self.mapToGlobal(self.rect().center())) self.sandbox = sandbox model = self.sandbox.model dE, dN = model.frame.dE, model.frame.dN def getKm(px, dp): return '%.2f km ' % (dp * px * 1e-3) self.spinEastPx.valueChanged.connect( lambda px: self.eastKm.setText(getKm(px, dE))) self.spinNorthPx.valueChanged.connect( lambda px: self.northKm.setText(getKm(px, dN))) self.applyButton.released.connect(self.updateValues) self.okButton.released.connect(self.updateValues) self.okButton.released.connect(self.close) self.setValues()
def __init__(self, delegate, ui_file, *args, **kwargs): QtGui.QDialog.__init__(self, *args, **kwargs) loadUi(get_resource(ui_file), self) self.delegate = delegate self.delegate.sourceParametersChanged.connect( self.getSourceParameters) self.applyButton.released.connect( self.setSourceParameters) self.okButton.released.connect( self.setSourceParameters) self.okButton.released.connect( self.close)
def __init__(self, *args, **kwargs): QtGui.QDialog.__init__(self, *args, **kwargs) loadUi(get_resource('dialog_config.ui'), self) self.ok_button.released.connect( self.setAttributes) self.ok_button.released.connect( self.close) self.apply_button.released.connect( self.setAttributes) self.vector_color_picker = QtGui.QColorDialog(self) self.vector_color_picker.\ setCurrentColor(QtGui.QColor(*config.vector_color)) self.vector_color_picker.\ setOption(self.vector_color_picker.ShowAlphaChannel) self.vector_color_picker.colorSelected.connect( self.updateVectorColor) self.vector_color_picker.setModal(True) self.vector_color.clicked.connect( self.vector_color_picker.show) self.vector_color.setValue = self.setButtonColor self.vector_color.value = self.getButtonColor self.chooseStoreDirButton.released.connect( self.chooseStoreDir) self.completer_model.setRootPath('') self.completer.setParent(self.default_gf_dir) self.default_gf_dir.setCompleter(self.completer) self.getAttributes()
def aboutDialog(self): self._about = QtGui.QDialog() loadUi(get_resource('about.ui'), baseinstance=self._about) return self._about
def __init__(self, img): QtGui.QDialog.__init__(self) self.image = QtSvg.QSvgWidget(img) self.setWindowTitle(QtGui.QApplication.translate("RebarTool", "Detailed description", None)) self.verticalLayout = QtGui.QVBoxLayout(self) self.verticalLayout.addWidget(self.image)
def __init__(self, parent, footprintlist): QtGui.QDialog.__init__(self, parent) self.owner = parent self.combo_param_name = QtGui.QComboBox(); self.combo_param_name.setEditable(True) self.footprint_list = footprintlist self.list_widget = PartTreeWidget(self) self.list_widget.setColumnCount(4) self.btn_load_bom = QtGui.QPushButton("load Field from xml-BOM") self.gridlayout = QtGui.QGridLayout() self.label = QtGui.QLabel("Field name:") self.gridlayout.addWidget(self.label,0,0,1,0) self.gridlayout.addWidget(self.btn_load_bom,1,1) self.gridlayout.addWidget(self.combo_param_name,1,0) self.gridlayout.addWidget(self.list_widget,2,0,1,0) self.label.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Minimum) self.combo_param_name.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Minimum) self.list_widget.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,QtGui.QSizePolicy.MinimumExpanding) self.param_names = [] settings = QtCore.QSettings("./KicadSolderTool.ini",QtCore.QSettings.IniFormat) size = settings.beginReadArray("param_names") for i in range(size): settings.setArrayIndex(i) self.param_names.append(settings.value("key")) settings.endArray() self.combo_param_name.addItems(self.param_names) self.combo_param_name.setCurrentIndex(int(settings.value("recent_field_name",0))) self.setLayout(self.gridlayout) for footprint in self.footprint_list: if footprint['bot']: caption = 'bot' else: caption = 'top' if footprint['other_side']: caption += "(also other side)" item = QtGui.QTreeWidgetItem(caption) item.setText(0,footprint['ref']) item.setText(1,caption) item.setText(2,footprint['val']) item.setCheckState(0,QtCore.Qt.Unchecked) self.list_widget.addTopLevelItem(item) for i in range(self.list_widget.columnCount()): self.list_widget.resizeColumnToContents(i); self.setMinimumWidth(600) self.show() self.connect(self.list_widget, QtCore.SIGNAL("itemSelectionChanged()"), self.on_select) self.connect(self.btn_load_bom, QtCore.SIGNAL("clicked()"), self.on_load_bom)
def __init__(self, sql, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle(u'Import database') self.sql = sql # file self.filePath = QtGui.QLineEdit('') self.filePath.setReadOnly(True) filePathButton = QtGui.QPushButton('...') self.connect(filePathButton, QtCore.SIGNAL("clicked()"), self.chooseFile) filePathFrame = QtGui.QFrame() filePathFrame.setObjectName('lay_path_widget') filePathFrame.setStyleSheet('''#lay_path_widget {background-color:#fff; border:1px solid rgb(199, 199, 199); padding: 5px;}''') filePathLayout = QtGui.QHBoxLayout(filePathFrame) filePathLayout.addWidget(QtGui.QLabel(u'File:\t')) filePathLayout.addWidget(self.filePath) filePathLayout.addWidget(filePathButton) filePathLayout.setContentsMargins(0, 0, 0, 0) # tabs self.tabs = QtGui.QTabWidget() self.tabs.setTabPosition(QtGui.QTabWidget.West) self.tabs.setObjectName('tabs_widget') self.tabs.addTab(self.tabCategories(), u'Categories') self.tabs.addTab(self.tabModels(), u'Models') self.tabs.setTabEnabled(1, False) self.connect(self.tabs, QtCore.SIGNAL("currentChanged (int)"), self.activeModelsTab) # buttons buttons = QtGui.QDialogButtonBox() buttons.addButton("Cancel", QtGui.QDialogButtonBox.RejectRole) buttons.addButton("Import", QtGui.QDialogButtonBox.AcceptRole) self.connect(buttons, QtCore.SIGNAL("accepted()"), self, QtCore.SLOT("accept()")) self.connect(buttons, QtCore.SIGNAL("rejected()"), self, QtCore.SLOT("reject()")) buttonsFrame = QtGui.QFrame() buttonsFrame.setObjectName('lay_path_widget') buttonsFrame.setStyleSheet('''#lay_path_widget {background-color:#fff; border:1px solid rgb(199, 199, 199); padding: 5px;}''') buttonsLayout = QtGui.QHBoxLayout(buttonsFrame) buttonsLayout.addWidget(buttons) buttonsLayout.setContentsMargins(0, 0, 0, 0) # main layout lay = QtGui.QGridLayout(self) lay.addWidget(filePathFrame, 0, 0, 1, 1) lay.addWidget(self.tabs, 1, 0, 1, 1) lay.addWidget(buttonsFrame, 2, 0, 1, 1) lay.setRowStretch(1, 10) lay.setContentsMargins(5, 5, 5, 5)
def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle(u"Create drilling map") # # Output file format self.formatList = QtGui.QComboBox() for i, j in exportList.items(): self.formatList.addItem(j['name'], i) # Output directory self.pathToFile = QtGui.QLineEdit('') self.pathToFile.setReadOnly(True) zmianaSciezki = QtGui.QPushButton('...') zmianaSciezki.setToolTip(u'Change path') QtCore.QObject.connect(zmianaSciezki, QtCore.SIGNAL("pressed ()"), self.zmianaSciezkiF) # buttons saveButton = QtGui.QPushButton(u"Export") self.connect(saveButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT("accept()")) closeButton = QtGui.QPushButton(u"Close") self.connect(closeButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT('close()')) packageFooter = QtGui.QHBoxLayout() packageFooter.addStretch(10) packageFooter.addWidget(saveButton) packageFooter.addWidget(closeButton) packageFooter.setContentsMargins(10, 0, 10, 10) # header icon = QtGui.QLabel('') icon.setPixmap(QtGui.QPixmap(":/data/img/drill-icon.png")) headerWidget = QtGui.QWidget() headerWidget.setStyleSheet("padding: 10px; border-bottom: 1px solid #dcdcdc; background-color:#FFF;") headerLay = QtGui.QGridLayout(headerWidget) headerLay.addWidget(icon, 0, 0, 1, 1) headerLay.setContentsMargins(0, 0, 0, 0) ######## centerLay = QtGui.QGridLayout() centerLay.addWidget(QtGui.QLabel(u'Output file format:'), 0, 0, 1, 1) centerLay.addWidget(self.formatList, 0, 1, 1, 2) centerLay.addWidget(QtGui.QLabel(u'Output directory:'), 1, 0, 1, 1) centerLay.addWidget(self.pathToFile, 1, 1, 1, 1) centerLay.addWidget(zmianaSciezki, 1, 2, 1, 1) centerLay.setContentsMargins(10, 20, 10, 20) mainLay = QtGui.QVBoxLayout(self) mainLay.addWidget(headerWidget) mainLay.addLayout(centerLay) mainLay.addStretch(10) mainLay.addLayout(packageFooter) mainLay.setContentsMargins(0, 0, 0, 0) # self.formatList.setCurrentIndex(self.formatList.findData('dxf'))
def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle(u"Export hole locations report") # Output directory self.pathToFile = QtGui.QLineEdit('') self.pathToFile.setReadOnly(True) zmianaSciezki = QtGui.QPushButton('...') zmianaSciezki.setToolTip(u'Change path') QtCore.QObject.connect(zmianaSciezki, QtCore.SIGNAL("pressed ()"), self.zmianaSciezkiF) # header icon = QtGui.QLabel('') icon.setPixmap(QtGui.QPixmap(":/data/img/drill-icon.png")) headerWidget = QtGui.QWidget() headerWidget.setStyleSheet("padding: 10px; border-bottom: 1px solid #dcdcdc; background-color:#FFF;") headerLay = QtGui.QGridLayout(headerWidget) headerLay.addWidget(icon, 0, 0, 1, 1) headerLay.setContentsMargins(0, 0, 0, 0) # buttons saveButton = QtGui.QPushButton(u"Export") self.connect(saveButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT("accept()")) closeButton = QtGui.QPushButton(u"Close") self.connect(closeButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT('close()')) packageFooter = QtGui.QHBoxLayout() packageFooter.addStretch(10) packageFooter.addWidget(saveButton) packageFooter.addWidget(closeButton) packageFooter.setContentsMargins(10, 0, 10, 10) # report self.reportPrev = QtGui.QTextEdit() ######## centerLay = QtGui.QGridLayout() centerLay.addWidget(QtGui.QLabel(u'Output directory:'), 0, 0, 1, 1) centerLay.addWidget(self.pathToFile, 0, 1, 1, 1) centerLay.addWidget(zmianaSciezki, 0, 2, 1, 1) centerLay.addWidget(self.reportPrev, 1, 0, 1, 3) centerLay.setContentsMargins(10, 20, 10, 20) mainLay = QtGui.QVBoxLayout(self) mainLay.addWidget(headerWidget) mainLay.addLayout(centerLay) mainLay.addLayout(packageFooter) mainLay.setContentsMargins(0, 0, 0, 0) # self.showReport()
def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self.setWindowTitle(u"Centroid") # # Output directory self.pathToFile = QtGui.QLineEdit('') self.pathToFile.setReadOnly(True) zmianaSciezki = QtGui.QPushButton('...') zmianaSciezki.setToolTip(u'Change path') QtCore.QObject.connect(zmianaSciezki, QtCore.SIGNAL("pressed ()"), self.zmianaSciezkiF) # header icon = QtGui.QLabel('') icon.setPixmap(QtGui.QPixmap(":/data/img/exportBOM.png")) headerWidget = QtGui.QWidget() headerWidget.setStyleSheet("padding: 10px; border-bottom: 1px solid #dcdcdc; background-color:#FFF;") headerLay = QtGui.QGridLayout(headerWidget) headerLay.addWidget(icon, 0, 0, 1, 1) headerLay.setContentsMargins(0, 0, 0, 0) # buttons saveButton = QtGui.QPushButton(u"Export") self.connect(saveButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT("accept()")) closeButton = QtGui.QPushButton(u"Close") self.connect(closeButton, QtCore.SIGNAL("clicked ()"), self, QtCore.SLOT('close()')) packageFooter = QtGui.QHBoxLayout() packageFooter.addStretch(10) packageFooter.addWidget(saveButton) packageFooter.addWidget(closeButton) packageFooter.setContentsMargins(10, 0, 10, 10) # report self.reportPrev = QtGui.QTextEdit() ######## centerLay = QtGui.QGridLayout() centerLay.addWidget(QtGui.QLabel(u'Output directory:'), 0, 0, 1, 1) centerLay.addWidget(self.pathToFile, 0, 1, 1, 1) centerLay.addWidget(zmianaSciezki, 0, 2, 1, 1) centerLay.addWidget(self.reportPrev, 1, 0, 1, 3) centerLay.setContentsMargins(10, 20, 10, 20) mainLay = QtGui.QVBoxLayout(self) mainLay.addWidget(headerWidget) mainLay.addLayout(centerLay) mainLay.addLayout(packageFooter) mainLay.setContentsMargins(0, 0, 0, 0) # self.showReport()
def setupWin(self): self.setWindowTitle("UITranslator" + " - v" + self.version + " - host: " + hostMode) self.setGeometry(300, 300, 300, 300) #------------------------------ # auto window icon setup path = os.path.join(os.path.dirname(self.location),'icons','UITranslator.png') self.setWindowIcon(QtGui.QIcon(path)) #------------------------------ # initial win drag position self.drag_position=QtGui.QCursor.pos() #------------------------------ # template list: for frameless or always on top option #------------------------------ # - template : keep ui always on top of all; # While in Maya, dont set Maya as its parent ''' self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) ''' # - template: hide ui border frame; # While in Maya, use QDialog instead, as QMainWindow will make it disappear ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint) ''' # - template: best solution for Maya QDialog without parent, for always on-Top frameless ui ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) ''' # - template: for transparent and non-regular shape ui # note: use it if you set main ui to transparent, and want to use alpha png as irregular shape window # note: black color better than white for better look of semi trans edge, like pre-mutiply ''' self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setStyleSheet("background-color: rgba(0, 0, 0,0);") ''' ############################################# # customized SUPER quick ui function for speed up programming #############################################
def setupUI(self): #------------------------------ # main_layout auto creation for holding all the UI elements #------------------------------ main_layout = None if isinstance(self, QtWidgets.QMainWindow): main_widget = QtWidgets.QWidget() self.setCentralWidget(main_widget) main_layout = self.quickLayout('vbox', 'main_layout') # grid for auto fill window size main_widget.setLayout(main_layout) else: # main_layout for QDialog main_layout = self.quickLayout('vbox', 'main_layout') self.setLayout(main_layout) #------------------------------ # user ui creation part #------------------------------ # + template: qui version since universal tool template v7 # - no extra variable name, all text based creation and reference self.qui('source_txt | process_btn;Process and Update', 'upper_vbox') self.qui('upper_vbox | result_txt', 'input_split;v') self.qui('filePath_input | fileLoad_btn;Load | fileExport_btn;Export', 'fileBtn_layout;hbox') self.qui('input_split | fileBtn_layout', 'main_layout') # - template : quickUI version since universal tool template v6 ''' upper_layout = self.quickUI(["source_txt;QTextEdit","process_btn;QPushButton;Process and Update"],"upper_QVBoxLayout") upper_layout.setContentsMargins(0,0,0,0) input_split = self.quickSplitUI("input_split", [ upper_layout, self.quickUI(["result_txt;QTextEdit"])[0] ], "v") fileBtn_layout = self.quickUI(["filePath_input;QLineEdit", "fileLoad_btn;QPushButton;Load", "fileExport_btn;QPushButton;Export"],"fileBtn_QHBoxLayout") self.quickUI([input_split, fileBtn_layout], main_layout) ''' # - template : invisible but functional button ''' self.uiList['secret_btn'] = QtWidgets.QPushButton(self) self.uiList['secret_btn'].setText("") self.uiList['secret_btn'].setGeometry(0, 0, 50, 20) self.uiList['secret_btn'].setStyleSheet("QPushButton{background-color: rgba(0, 0, 0,0);} QPushButton:pressed{background-color: rgba(0, 0, 0,0); border: 0px;} QPushButton:hover{background-color: rgba(0, 0, 0,0); border: 0px;}") #:hover:pressed:focus:hover:disabled ''' #------------- end ui creation -------------------- keep_margin_layout = ['main_layout'] for name, each in self.uiList.items(): if isinstance(each, QtWidgets.QLayout) and name not in keep_margin_layout and not name.endswith('_grp_layout'): each.setContentsMargins(0, 0, 0, 0) self.quickInfo('Ready')
def setupWin(self): self.setWindowTitle("UniversalToolUI" + " - v" + self.version + " - host: " + hostMode) self.setGeometry(500, 300, 250, 110) # self.resize(250,250) #------------------------------ # auto window icon setup path = os.path.join(os.path.dirname(self.location),'icons','UniversalToolUI.png') self.setWindowIcon(QtGui.QIcon(path)) #------------------------------ # initial win drag position self.drag_position=QtGui.QCursor.pos() #------------------------------ # template list: for frameless or always on top option #------------------------------ # - template : keep ui always on top of all; # While in Maya, dont set Maya as its parent ''' self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) ''' # - template: hide ui border frame; # While in Maya, use QDialog instead, as QMainWindow will make it disappear ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint) ''' # - template: best solution for Maya QDialog without parent, for always on-Top frameless ui ''' self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) ''' # - template: for transparent and non-regular shape ui # note: use it if you set main ui to transparent, and want to use alpha png as irregular shape window # note: black color better than white for better look of semi trans edge, like pre-mutiply ''' self.setAttribute(QtCore.Qt.WA_TranslucentBackground) self.setStyleSheet("background-color: rgba(0, 0, 0,0);") ''' ############################################# # customized SUPER quick ui function for speed up programming #############################################