當前位置: 首頁>>代碼示例>>Python>>正文


Python QListWidget.insertItem方法代碼示例

本文整理匯總了Python中PySide.QtGui.QListWidget.insertItem方法的典型用法代碼示例。如果您正苦於以下問題:Python QListWidget.insertItem方法的具體用法?Python QListWidget.insertItem怎麽用?Python QListWidget.insertItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PySide.QtGui.QListWidget的用法示例。


在下文中一共展示了QListWidget.insertItem方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: MainWindow

# 需要導入模塊: from PySide.QtGui import QListWidget [as 別名]
# 或者: from PySide.QtGui.QListWidget import insertItem [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:
#.........這裏部分代碼省略.........
開發者ID:nikolap,項目名稱:pdfmerger,代碼行數:103,代碼來源:pdfMerger.py


注:本文中的PySide.QtGui.QListWidget.insertItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。