本文整理汇总了Python中PySide.QtGui.QListWidget.item方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.item方法的具体用法?Python QListWidget.item怎么用?Python QListWidget.item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QListWidget
的用法示例。
在下文中一共展示了QListWidget.item方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConfigEditor
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import item [as 别名]
class ConfigEditor(QMainWindow):
def __init__(self, app, cfg, title='Config Editor'):
super(ConfigEditor, self).__init__()
self.app = app
self.config = cfg
self.title = title
def setup(self):
self.dirty = False
self.def_cfg = copy.deepcopy(self.config)
self.config.update_from_user_file()
self.base_cfg = copy.deepcopy(self.config)
self.categories = QListWidget()
#self.categories.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Expanding)
self.settings = QStackedWidget()
#self.categories.setSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.Expanding)
QObject.connect(self.categories, SIGNAL('itemSelectionChanged()'), self.category_selected)
self.widget_list = {}
for cat in self.config.get_categories():
self.widget_list[cat] = {}
longest_cat = 0
for cat in self.config.get_categories():
if len(cat) > longest_cat:
longest_cat = len(cat)
self.categories.addItem(cat)
settings_layout = QGridLayout()
r = 0
c = 0
for setting in self.config.get_settings(cat):
info = self.config.get_setting(cat, setting, True)
s = QWidget()
s.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed)
sl = QVBoxLayout()
label = QLabel()
if info.has_key('alias'):
label.setText(info['alias'])
else:
label.setText(setting)
if info.has_key('about'):
label.setToolTip(info['about'])
sl.addWidget(label)
if info['type'] == constants.CT_LINEEDIT:
w = LineEdit(self, self.config,cat,setting,info)
elif info['type'] == constants.CT_CHECKBOX:
w = CheckBox(self, self.config,cat,setting,info)
elif info['type'] == constants.CT_SPINBOX:
w = SpinBox(self, self.config,cat,setting,info)
elif info['type'] == constants.CT_DBLSPINBOX:
w = DoubleSpinBox(self, self.config,cat,setting,info)
elif info['type'] == constants.CT_COMBO:
w = ComboBox(self, self.config,cat,setting,info)
w.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed)
self.widget_list[cat][setting] = w
sl.addWidget(w)
s.setLayout(sl)
c = self.config.config[cat].index(setting) % 2
settings_layout.addWidget(s, r, c)
if c == 1:
r += 1
settings = QWidget()
settings.setLayout(settings_layout)
settings_scroller = QScrollArea()
settings_scroller.setWidget(settings)
settings_scroller.setWidgetResizable(True)
self.settings.addWidget(settings_scroller)
font = self.categories.font()
fm = QFontMetrics(font)
self.categories.setMaximumWidth(fm.widthChar('X')*(longest_cat+4))
self.main = QWidget()
self.main_layout = QVBoxLayout()
self.config_layout = QHBoxLayout()
self.config_layout.addWidget(self.categories)
self.config_layout.addWidget(self.settings)
self.mainButtons = QDialogButtonBox(QDialogButtonBox.RestoreDefaults | QDialogButtonBox.Reset | QDialogButtonBox.Apply)
self.main_apply = self.mainButtons.button(QDialogButtonBox.StandardButton.Apply)
self.main_reset = self.mainButtons.button(QDialogButtonBox.StandardButton.Reset)
self.main_defaults = self.mainButtons.button(QDialogButtonBox.StandardButton.LastButton)
QObject.connect(self.mainButtons, SIGNAL('clicked(QAbstractButton *)'), self.mainbutton_clicked)
self.dirty_check()
self.main_layout.addLayout(self.config_layout)
self.main_layout.addWidget(self.mainButtons)
self.main.setLayout(self.main_layout)
self.setCentralWidget(self.main)
self.setWindowTitle(self.title)
self.setUnifiedTitleAndToolBarOnMac(True)
#.........这里部分代码省略.........
示例2: MainWindow
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import item [as 别名]
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.resize(800,600)
self.setWindowTitle('PDF Merger')
about = QAction('About', self)
self.connect(about, SIGNAL('triggered()'), self.show_about)
exit = QAction('Exit', self)
exit.setShortcut('Ctrl+Q')
self.connect(exit, SIGNAL('triggered()'), SLOT('close()'))
self.statusBar()
menubar = self.menuBar()
file = menubar.addMenu('File')
file.addAction(about)
file.addAction(exit)
self.main_widget = QWidget(self)
self.setCentralWidget(self.main_widget)
self.up_down_widget = QWidget(self)
self.options_widget = QWidget(self)
input_files_label = QLabel("Input PDFs\nThis is the order in which the files will be merged too")
self.files_list = QListWidget()
self.files_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
add_button = QPushButton("Add PDF(s) to merge...")
add_button.clicked.connect(self.clicked_add)
up_button = QPushButton("Up")
up_button.clicked.connect(self.move_file_up)
down_button = QPushButton("Down")
down_button.clicked.connect(self.move_file_down)
remove_button = QPushButton("Remove PDF")
remove_button.clicked.connect(self.remove_file)
select_path_label = QLabel("Output PDF")
self.dest_path_edit = QLineEdit()
self.dest_path_edit.setReadOnly(True)
select_path = QPushButton("Select...")
select_path.clicked.connect(self.select_save_path)
start = QPushButton("Start")
start.clicked.connect(self.merge_pdf)
up_down_vbox = QVBoxLayout(self.up_down_widget)
up_down_vbox.addWidget(up_button)
up_down_vbox.addWidget(down_button)
up_down_vbox.addWidget(remove_button)
self.up_down_widget.setLayout(up_down_vbox)
group_input = QGroupBox()
grid_input = QGridLayout()
grid_input.addWidget(add_button, 0, 0)
grid_input.addWidget(input_files_label, 1, 0)
grid_input.addWidget(self.files_list, 2, 0)
grid_input.addWidget(self.up_down_widget, 2, 1)
group_input.setLayout(grid_input)
group_output = QGroupBox()
grid_output = QGridLayout()
grid_output.addWidget(select_path_label, 0, 0)
grid_output.addWidget(self.dest_path_edit, 1, 0)
grid_output.addWidget(select_path, 1, 1)
group_output.setLayout(grid_output)
vbox_options = QVBoxLayout(self.options_widget)
vbox_options.addWidget(group_input)
vbox_options.addWidget(group_output)
vbox_options.addWidget(start)
self.options_widget.setLayout(vbox_options)
splitter_filelist = QSplitter()
splitter_filelist.setOrientation(Qt.Vertical)
splitter_filelist.addWidget(self.options_widget)
vbox_main = QVBoxLayout(self.main_widget)
vbox_main.addWidget(splitter_filelist)
vbox_main.setContentsMargins(0,0,0,0)
def show_about(self):
#TODO add hyperlinks and create simple base website
#TODO versioning system
QMessageBox.about(self, 'About', 'PDF Merger\n2013 Nikola Peric\n\n'
+ 'http://www.example.com/\nhttps://github.com/nikolap/pdfmerger/\n\n'
+ 'Licensed under The MIT License\nhttp://opensource.org/licenses/MIT' )
def clicked_add(self):
fname, _ = QFileDialog.getOpenFileNames(self, 'Select two or more PDFs to merge',
QDir.homePath(), "*.pdf")
self.files_list.addItems(fname)
def move_file_up(self):
sorted_selected_items = self.get_sorted_selected_items()
if 0 not in sorted_selected_items:
for row in sorted_selected_items:
item = self.files_list.takeItem(row)
self.files_list.insertItem(row - 1, item)
def move_file_down(self):
sorted_selected_items = self.get_sorted_selected_items(descending=True)
if (self.files_list.count() - 1) not in sorted_selected_items:
for row in sorted_selected_items:
#.........这里部分代码省略.........
示例3: UiMain
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import item [as 别名]
class UiMain(QMainWindow):
""" The main gui interface, invokes all windows and ties everything
together
"""
def __init__(self):
""" automatically called __init__ function """
super(UiMain, self).__init__()
# initialize all the variables that are going to be defined in the
# future
self.update_dialog = None
self.update_dialog_lbl = None
self.app_select_box = None
self.selector_lbl = None
self.current_playing_lbl = None
self.current_playing = None
self.misc_messages = None
self.start_btn = None
self.output_dir_lbl = None
self.select_output_dir_btn = None
self.output_cur_dir_lbl = None
self.active_items_list = None
self.inactive_items_list = None
self.switch_active_item_button_off = None
self.switch_active_item_button_on = None
self.switch_output_split_btn = None
self.switch_output_split_lbl = None
# initialize the system tray
# self.system_tray = QSystemTrayIcon(self)
# self.system_tray.setIcon(QIcon(resource_path('icon.png')))
# self.system_tray.show()
# self.system_tray.setToolTip('SMG')
# self.system_tray.activated.connect(self.on_systray_activated)
# initialize the main window
self.setObjectName('self')
self.setWindowTitle('SMG - By Azeirah')
self.resize(400, 250)
# Gives the self an icon
self.setWindowIcon(QIcon(resource_path('icon.png')))
# create the tabs
# the tab widget itself
self.tabbed_windows = QTabWidget(self)
self.tabbed_windows.resize(400, 300)
# tab 1, contains the music player selection
self.music_players = QFrame()
# tab 2, contains options
self.options = QFrame()
self.tabbed_windows.addTab(self.music_players, 'Music players')
self.tabbed_windows.addTab(self.options, 'Options')
# initializes the two tabs, with all the code down below
self.tab_music_players()
self.tab_options()
# shows the main window
self.show()
def closeEvent(self, event):
""" an automatically called function when the program is about to
close.
"""
# Stops all Threads. These would continue to run in the background
# Even if the window was closed.
Main.running = False
# close the ZuneNowPlaying.exe process
if Constants.SUBP:
Constants.SUBP.kill()
def changeEvent(self, event):
# if event.type() == QEvent.WindowStateChange:
# if self.isMinimized():
# event.ignore()
# self.hide()
# self.system_tray.showMessage('Running', 'Running in the
# background.')
# return
super(UiMain, self).changeEvent(event)
def on_systray_activated(self, reason):
if reason == QSystemTrayIcon.DoubleClick:
self.show()
@staticmethod
def toggle_split(event):
# 0 = Qt.Unchecked The item is unchecked.
# 1 = Qt.PartiallyChecked The item is partially checked. Items in
# hierarchical models may be partially checked if some, but not all,
# of
# their children are checked.
# 2 = Qt.Checked The item is checked.
#.........这里部分代码省略.........
示例4: MainControl
# 需要导入模块: from PySide.QtGui import QListWidget [as 别名]
# 或者: from PySide.QtGui.QListWidget import item [as 别名]
class MainControl(QWidget):
toChangeChunk = Signal(tuple)
toChangeSlice = Signal(int)
def __init__(self, parent):
super(MainControl, self).__init__(parent)
self.parent = parent
self.selectedMinerals = parent.selectedMinerals
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
lb0 = QLabel('Minecraft Prism chunk minerals finder')
lb1 = QLabel('Chunk X')
lb2 = QLabel('Chunk Z')
lb3 = QLabel('Show deposits of:')
lb4 = QLabel('Slice Elevation')
#lb0.setFrameStyle(QFrame.Box)
lb0.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
lb2.setAlignment(Qt.AlignVCenter | Qt.AlignRight)
self.txtChunkX = QLineEdit()
self.txtChunkZ = QLineEdit()
self.txtElevation = QLineEdit(str(self.parent.presenter.elevation))
self.txtChunkX.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
self.txtChunkZ.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
self.txtElevation.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
self.btnViewChunk = QPushButton('View Chunk')
self.btnViewChunk.clicked.connect(self.btnViewChunk_OnClick)
self.btnSliceUp = QPushButton('Slice Up')
self.btnSliceUp.clicked.connect(self.btnSliceUp_OnClick)
self.btnSliceDown = QPushButton('Slice Down')
self.btnSliceDown.clicked.connect(self.btnSliceDown_OnClick)
self.lstMinerals = QListWidget()
self.lstMinerals.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.lstMinerals.addItem(SelectedMineral('Gold', 14))
self.lstMinerals.addItem(SelectedMineral('Iron', 15))
self.lstMinerals.addItem(SelectedMineral('Diamond', 56))
self.lstMinerals.addItem(SelectedMineral('Redstone', 73))
self.lstMinerals.addItem(SelectedMineral('Obsidian', 49))
self.lstMinerals.addItem(SelectedMineral('Coal', 16))
self.lstMinerals.addItem(SelectedMineral('Lazurit', 21))
self.lstMinerals.setCurrentItem(self.lstMinerals.item(0))
self.lstMinerals.itemSelectionChanged.connect(self.onSelectedMinerals)
elevBox = QHBoxLayout()
elevBox.addWidget(lb4)
elevBox.addWidget(self.txtElevation)
elevBox.addWidget(self.btnSliceUp)
elevBox.addWidget(self.btnSliceDown)
ly = QGridLayout()
ly.addWidget(lb0, 0, 0, 1, 4)
ly.addWidget(lb1, 1, 0, 1, 1)
ly.addWidget(self.txtChunkX, 1, 1, 1, 1)
ly.addWidget(lb2, 1, 2, 1, 1)
ly.addWidget(self.txtChunkZ, 1, 3, 1, 1)
ly.addWidget(lb3, 2, 0, 1, 2)
ly.addWidget(self.lstMinerals, 2, 2, 1, 2)
ly.addWidget(self.btnViewChunk, 3, 1, 1, 2)
ly.addLayout(elevBox, 4, 0, 1, 4)
ly.setColumnStretch(0, 20)
ly.setColumnStretch(1, 15)
ly.setColumnStretch(2, 46)
ly.setColumnStretch(3, 19)
self.setLayout(ly)
def sizeHint(self):
return QSize(self.parent.controlsWidth, 180)
def btnViewChunk_OnClick(self):
chX = int(self.txtChunkX.text())
chZ = int(self.txtChunkZ.text())
self.toChangeChunk.emit((chX, chZ))
def btnSliceUp_OnClick(self):
elev = int(self.txtElevation.text()) + 1
if elev < 64:
self.toChangeSlice.emit(elev)
self.txtElevation.setText(str(elev))
def btnSliceDown_OnClick(self):
elev = int(self.txtElevation.text()) - 1
if elev > -1:
self.toChangeSlice.emit(elev)
self.txtElevation.setText(str(elev))
def onSelectedMinerals(self):
selMin = []
for item in self.lstMinerals.selectedItems():
selMin.append(item.blockCode)
self.parent.selectedMinerals.setSelectedMinerals(selMin)