本文整理汇总了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:
#.........这里部分代码省略.........