本文整理汇总了Python中PyQt4.Qt.QTableView类的典型用法代码示例。如果您正苦于以下问题:Python QTableView类的具体用法?Python QTableView怎么用?Python QTableView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTableView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parent=None):
QTableView.__init__(self, parent)
self.rt_delegate = RichTextDelegate(self)
self.setSelectionMode(self.SingleSelection)
self.setAlternatingRowColors(True)
self.setSelectionBehavior(self.SelectRows)
self.setIconSize(QSize(24, 24))
self.clicked.connect(self.show_details)
self.doubleClicked.connect(self.select_index)
self.setSortingEnabled(True)
示例2: keyPressEvent
def keyPressEvent(self, ev):
ret = QTableView.keyPressEvent(self, ev)
if ev.key() in (Qt.Key_PageUp, Qt.Key_PageDown, Qt.Key_Up, Qt.Key_Down):
idx = self.currentIndex()
if idx.isValid():
self.scrollTo(idx)
return ret
示例3: mousePressEvent
def mousePressEvent(self, event):
ep = event.pos()
if (
self.indexAt(ep) in self.selectionModel().selectedIndexes()
and event.button() == Qt.LeftButton
and not self.event_has_mods()
):
self.drag_start_pos = ep
return QTableView.mousePressEvent(self, event)
示例4: _initialize_controls
def _initialize_controls(self):
self.setWindowTitle(_("User plugins"))
self.setWindowIcon(QIcon(I("plugins/plugin_updater.png")))
layout = QVBoxLayout(self)
self.setLayout(layout)
title_layout = ImageTitleLayout(self, "plugins/plugin_updater.png", _("User Plugins"))
layout.addLayout(title_layout)
header_layout = QHBoxLayout()
layout.addLayout(header_layout)
self.filter_combo = PluginFilterComboBox(self)
self.filter_combo.setMinimumContentsLength(20)
self.filter_combo.currentIndexChanged[int].connect(self._filter_combo_changed)
header_layout.addWidget(QLabel(_("Filter list of plugins") + ":", self))
header_layout.addWidget(self.filter_combo)
header_layout.addStretch(10)
self.plugin_view = QTableView(self)
self.plugin_view.horizontalHeader().setStretchLastSection(True)
self.plugin_view.setSelectionBehavior(QAbstractItemView.SelectRows)
self.plugin_view.setSelectionMode(QAbstractItemView.SingleSelection)
self.plugin_view.setAlternatingRowColors(True)
self.plugin_view.setSortingEnabled(True)
self.plugin_view.setIconSize(QSize(28, 28))
layout.addWidget(self.plugin_view)
details_layout = QHBoxLayout()
layout.addLayout(details_layout)
forum_label = QLabel('<a href="http://www.foo.com/">Plugin Forum Thread</a>', self)
forum_label.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard)
forum_label.linkActivated.connect(self._forum_label_activated)
details_layout.addWidget(QLabel(_("Description") + ":", self), 0, Qt.AlignLeft)
details_layout.addWidget(forum_label, 1, Qt.AlignRight)
self.description = QLabel(self)
self.description.setFrameStyle(QFrame.Panel | QFrame.Sunken)
self.description.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.description.setMinimumHeight(40)
self.description.setWordWrap(True)
layout.addWidget(self.description)
self.button_box = QDialogButtonBox(QDialogButtonBox.Close)
self.button_box.rejected.connect(self.reject)
self.finished.connect(self._finished)
self.install_button = self.button_box.addButton(_("&Install"), QDialogButtonBox.AcceptRole)
self.install_button.setToolTip(_("Install the selected plugin"))
self.install_button.clicked.connect(self._install_clicked)
self.install_button.setEnabled(False)
self.configure_button = self.button_box.addButton(
" " + _("&Customize plugin ") + " ", QDialogButtonBox.ResetRole
)
self.configure_button.setToolTip(_("Customize the options for this plugin"))
self.configure_button.clicked.connect(self._configure_clicked)
self.configure_button.setEnabled(False)
layout.addWidget(self.button_box)
示例5: keyPressEvent
def keyPressEvent(self, ev):
if ev == QKeySequence.Copy:
self.copy_to_clipboard()
ev.accept()
return
ret = QTableView.keyPressEvent(self, ev)
if ev.key() in (Qt.Key_PageUp, Qt.Key_PageDown, Qt.Key_Up, Qt.Key_Down):
idx = self.currentIndex()
if idx.isValid():
self.scrollTo(idx)
return ret
示例6: mouseMoveEvent
def mouseMoveEvent(self, event):
if not self.drag_allowed:
return
if self.drag_start_pos is None:
return QTableView.mouseMoveEvent(self, event)
if self.event_has_mods():
self.drag_start_pos = None
return
if not (event.buttons() & Qt.LeftButton) or \
(event.pos() - self.drag_start_pos).manhattanLength() \
< QApplication.startDragDistance():
return
index = self.indexAt(event.pos())
if not index.isValid():
return
drag = self.drag_data()
drag.exec_(Qt.CopyAction)
self.drag_start_pos = None
示例7: moveCursor
def moveCursor(self, action, modifiers):
orig = self.currentIndex()
index = QTableView.moveCursor(self, action, modifiers)
if action == QTableView.MovePageDown:
moved = index.row() - orig.row()
try:
rows = self.row_at_bottom() - self.row_at_top()
except TypeError:
rows = moved
if moved > rows:
index = self.model().index(orig.row() + rows, index.column())
elif action == QTableView.MovePageUp:
moved = orig.row() - index.row()
try:
rows = self.row_at_bottom() - self.row_at_top()
except TypeError:
rows = moved
if moved > rows:
index = self.model().index(orig.row() - rows, index.column())
elif action == QTableView.MoveHome and modifiers & Qt.ControlModifier:
return self.model().index(0, orig.column())
elif action == QTableView.MoveEnd and modifiers & Qt.ControlModifier:
return self.model().index(self.model().rowCount(QModelIndex()) - 1, orig.column())
return index
示例8: scrollContentsBy
def scrollContentsBy(self, dx, dy):
# Needed as Qt bug causes headerview to not always update when scrolling
QTableView.scrollContentsBy(self, dx, dy)
if dy != 0:
self.column_header.update()
示例9: __init__
def __init__(self, parent, modelcls=BooksModel, use_edit_metadata_dialog=True):
QTableView.__init__(self, parent)
self.gui = parent
self.setProperty('highlight_current_item', 150)
self.row_sizing_done = False
self.alternate_views = AlternateViews(self)
if not tweaks['horizontal_scrolling_per_column']:
self.setHorizontalScrollMode(self.ScrollPerPixel)
self.setEditTriggers(self.EditKeyPressed)
if tweaks['doubleclick_on_library_view'] == 'edit_cell':
self.setEditTriggers(self.DoubleClicked|self.editTriggers())
elif tweaks['doubleclick_on_library_view'] == 'open_viewer':
self.setEditTriggers(self.SelectedClicked|self.editTriggers())
self.doubleClicked.connect(parent.iactions['View'].view_triggered)
elif tweaks['doubleclick_on_library_view'] == 'edit_metadata':
# Must not enable single-click to edit, or the field will remain
# open in edit mode underneath the edit metadata dialog
if use_edit_metadata_dialog:
self.doubleClicked.connect(
partial(parent.iactions['Edit Metadata'].edit_metadata,
checked=False))
else:
self.setEditTriggers(self.DoubleClicked|self.editTriggers())
setup_dnd_interface(self)
self.setAlternatingRowColors(True)
self.setSelectionBehavior(self.SelectRows)
self.setShowGrid(False)
self.setWordWrap(False)
self.rating_delegate = RatingDelegate(self)
self.timestamp_delegate = DateDelegate(self)
self.pubdate_delegate = PubDateDelegate(self)
self.last_modified_delegate = DateDelegate(self,
tweak_name='gui_last_modified_display_format')
self.languages_delegate = LanguagesDelegate(self)
self.tags_delegate = CompleteDelegate(self, ',', 'all_tag_names')
self.authors_delegate = CompleteDelegate(self, '&', 'all_author_names', True)
self.cc_names_delegate = CompleteDelegate(self, '&', 'all_custom', True)
self.series_delegate = TextDelegate(self)
self.publisher_delegate = TextDelegate(self)
self.text_delegate = TextDelegate(self)
self.cc_text_delegate = CcTextDelegate(self)
self.cc_enum_delegate = CcEnumDelegate(self)
self.cc_bool_delegate = CcBoolDelegate(self)
self.cc_comments_delegate = CcCommentsDelegate(self)
self.cc_template_delegate = CcTemplateDelegate(self)
self.cc_number_delegate = CcNumberDelegate(self)
self.display_parent = parent
self._model = modelcls(self)
self.setModel(self._model)
self._model.count_changed_signal.connect(self.do_row_sizing,
type=Qt.QueuedConnection)
self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSortingEnabled(True)
self.selectionModel().currentRowChanged.connect(self._model.current_changed)
self.preserve_state = partial(PreserveViewState, self)
# {{{ Column Header setup
self.can_add_columns = True
self.was_restored = False
self.column_header = HeaderView(Qt.Horizontal, self)
self.setHorizontalHeader(self.column_header)
self.column_header.setMovable(True)
self.column_header.setClickable(True)
self.column_header.sectionMoved.connect(self.save_state)
self.column_header.setContextMenuPolicy(Qt.CustomContextMenu)
self.column_header.customContextMenuRequested.connect(self.show_column_header_context_menu)
self.column_header.sectionResized.connect(self.column_resized, Qt.QueuedConnection)
self.row_header = HeaderView(Qt.Vertical, self)
self.setVerticalHeader(self.row_header)
# }}}
self._model.database_changed.connect(self.database_changed)
hv = self.verticalHeader()
hv.setClickable(True)
hv.setCursor(Qt.PointingHandCursor)
self.selected_ids = []
self._model.about_to_be_sorted.connect(self.about_to_be_sorted)
self._model.sorting_done.connect(self.sorting_done,
type=Qt.QueuedConnection)
示例10: viewportEvent
def viewportEvent(self, event):
if (event.type() == event.ToolTip and not gprefs['book_list_tooltips']):
return False
return QTableView.viewportEvent(self, event)
示例11: __init__
def __init__(self, parent):
QTableView.__init__(self, parent)
self.setAcceptDrops(True)
示例12: MainWidget
class MainWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
# define periodic table widget for element selection
self.periodicTableWidget = widgets.PeriodicTableDialog()
# initial molecule Zmatrix (can be empty)
# self.inp = []
self.inp = [['H'],
['O', 1, 0.9],
['O', 2, 1.4, 1, 105.],
['H', 3, 0.9, 2, 105., 1, 120.]]
self.atomList = []
self.highList = []
self.labelList = []
self.fast = False
# define & initialize ZMatModel that will contain Zmatrix data
self.ZMatModel = QStandardItemModel(len(self.inp), 7, self)
self.ZMatTable = QTableView(self)
self.ZMatTable.setModel(self.ZMatModel)
self.ZMatTable.setFixedWidth(325)
#self.ZMatTable.installEventFilter(self)
#self.ZMatModel.installEventFilter(self)
self.ZMatModel.setHorizontalHeaderLabels(['atom','','bond','','angle','','dihedral'])
for j, width in enumerate([40, 22, 65, 22, 65, 22, 65]):
self.ZMatTable.setColumnWidth(j, width)
# populate the ZMatModel
self.populateZMatModel()
#define Menu bar menus and their actions
self.menuBar = QMenuBar(self)
fileMenu = self.menuBar.addMenu('&File')
editMenu = self.menuBar.addMenu('&Edit')
viewMenu = self.menuBar.addMenu('&View')
measureMenu = self.menuBar.addMenu('&Measure')
helpMenu = self.menuBar.addMenu('&Help')
readZmatAction = QAction('&Read &ZMat', self)
readZmatAction.setShortcut('Ctrl+O')
readZmatAction.setStatusTip('Read Zmat from file')
readZmatAction.triggered.connect(self.readZmat)
fileMenu.addAction(readZmatAction)
readXYZAction = QAction('&Read &XYZ', self)
readXYZAction.setShortcut('Ctrl+Shift+O')
readXYZAction.setStatusTip('Read XYZ from file')
readXYZAction.triggered.connect(self.readXYZ)
fileMenu.addAction(readXYZAction)
readGaussianAction = QAction('&Read &Gaussian log', self)
readGaussianAction.setShortcut('Ctrl+G')
readGaussianAction.setStatusTip('Read Gaussian log file')
readGaussianAction.triggered.connect(self.readGaussian)
fileMenu.addAction(readGaussianAction)
writeZmatAction = QAction('&Write &ZMat', self)
writeZmatAction.setShortcut('Ctrl+S')
writeZmatAction.setStatusTip('Write Zmat to file')
writeZmatAction.triggered.connect(self.writeZmat)
fileMenu.addAction(writeZmatAction)
writeXYZAction = QAction('&Write &XYZ', self)
writeXYZAction.setShortcut('Ctrl+Shift+S')
writeXYZAction.setStatusTip('Write XYZ from file')
writeXYZAction.triggered.connect(self.writeXYZ)
fileMenu.addAction(writeXYZAction)
exitAction = QAction('&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(qApp.quit)
fileMenu.addAction(exitAction)
addRowAction = QAction('&Add &row', self)
addRowAction.setShortcut('Ctrl+R')
addRowAction.setStatusTip('Add row to ZMatrix')
addRowAction.triggered.connect(self.addRow)
editMenu.addAction(addRowAction)
deleteRowAction = QAction('&Delete &row', self)
deleteRowAction.setShortcut('Ctrl+Shift+R')
deleteRowAction.setStatusTip('Delete row from ZMatrix')
deleteRowAction.triggered.connect(self.deleteRow)
editMenu.addAction(deleteRowAction)
addAtomAction = QAction('&Add &atom', self)
addAtomAction.setShortcut('Ctrl+A')
addAtomAction.setStatusTip('Add atom to ZMatrix')
addAtomAction.triggered.connect(self.buildB)
editMenu.addAction(addAtomAction)
drawModeMenu = QMenu('Draw mode', self)
viewMenu.addMenu(drawModeMenu)
fastDrawAction = QAction('&Fast draw', self)
fastDrawAction.triggered.connect(self.fastDraw)
normalDrawAction = QAction('&Normal draw', self)
normalDrawAction.triggered.connect(self.normalDraw)
#.........这里部分代码省略.........
示例13: __init__
#.........这里部分代码省略.........
a160 = CheckHash160(utxo.getRecipientScrAddr())
for pyAddr in self.dustTableModel.wlt.addrMap.values():
if a160 == pyAddr.getAddr160():
pubKey = pyAddr.binPublicKey65.toBinStr()
txoIdx = utxo.getTxOutIndex()
utxiList.append(UnsignedTxInput(rawTx, txoIdx, None, pubKey))
break
# Make copies, destroy them in the finally clause
privKeyMap = {}
for addrObj in self.dustTableModel.wlt.addrMap.values():
scrAddr = SCRADDR_P2PKH_BYTE + addrObj.getAddr160()
if self.dustTableModel.wlt.useEncryption and self.dustTableModel.wlt.isLocked:
# Target wallet is encrypted...
unlockdlg = DlgUnlockWallet(self.dustTableModel.wlt,
self.main, self.main, 'Unlock Wallet to Import')
if not unlockdlg.exec_():
QMessageBox.critical(self, 'Wallet is Locked', \
'Cannot send dust without unlocking the wallet!', \
QMessageBox.Ok)
return
privKeyMap[scrAddr] = addrObj.binPrivKey32_Plain.copy()
signedTx = PyCreateAndSignTx(utxiList,
[],
privKeyMap, SIGHASH_NONE|SIGHASH_ANYONECANPAY )
print "-------------"
print binary_to_hex(signedTx.serialize())
# sock = socket.create_connection(('dust-b-gone.bitcoin.petertodd.org',80))
# sock.send(signedTx.serialize())
# sock.send(b'\n')
# sock.close()
except socket.error as err:
QMessageBox.critical(self.main, tr('Negative Value'), tr("""
Failed to connect to dust-b-gone server: %s""" % err.strerror), QMessageBox.Ok)
except NegativeValueError:
QMessageBox.critical(self.main, tr('Negative Value'), tr("""
You must enter a positive value of at least 0.0000 0001
and less than %s for the dust limit.""" % MAX_DUST_LIMIT_STR), QMessageBox.Ok)
except TooMuchPrecisionError:
QMessageBox.critical(self.main.main, tr('Too much precision'), tr("""
Bitcoins can only be specified down to 8 decimal places.
The smallest unit of a Groestlcoin is 0.0000 0001 GRS.
Please enter a dust limit of at least 0.0000 0001 and less than %s.""" % MAX_DUST_LIMIT_STR), QMessageBox.Ok)
finally:
for scraddr in privKeyMap:
privKeyMap[scraddr].destroy()
self.main = main
self.lblHeader = QRichLabel(tr("""<b>Dust Outputs for Wallet: None Selected</b>"""), doWrap=False)
self.beGoneDustButton = QPushButton("Remove Dust")
self.beGoneDustButton.setEnabled(False)
self.main.connect(self.beGoneDustButton, SIGNAL('clicked()'), sendDust)
topRow = makeHorizFrame([self.lblHeader,'stretch'])
secondRow = makeHorizFrame([self.beGoneDustButton, 'stretch'])
self.dustLimitLabel = QLabel("Max Dust Value (GRS): ")
self.dustLimitText = QLineEdit()
self.dustLimitText.setFont(GETFONT('Fixed'))
self.dustLimitText.setMinimumWidth(tightSizeNChar(self.dustLimitText, 6)[0])
self.dustLimitText.setMaximumWidth(tightSizeNChar(self.dustLimitText, 12)[0])
self.dustLimitText.setAlignment(Qt.AlignRight)
self.dustLimitText.setText(coin2str(DEFAULT_DUST_LIMIT))
self.main.connect(self.dustLimitText, SIGNAL('textChanged(QString)'), updateDustLimit)
limitPanel = makeHorizFrame([self.dustLimitLabel, self.dustLimitText, 'stretch'])
self.dustTableModel = DustDisplayModel()
self.dustTableView = QTableView()
self.dustTableView.setModel(self.dustTableModel)
self.dustTableView.setSelectionMode(QTableView.NoSelection)
self.dustTableView.verticalHeader().setDefaultSectionSize(20)
self.dustTableView.verticalHeader().hide()
h = tightSizeNChar(self.dustTableView, 1)[1]
self.dustTableView.setMinimumHeight(2 * (1.3 * h))
self.dustTableView.setMaximumHeight(10 * (1.3 * h))
initialColResize(self.dustTableView, [100, .7, .3])
self.dustTableView.setContextMenuPolicy(Qt.CustomContextMenu)
self.lblTxioInfo = QRichLabel('')
self.lblTxioInfo.setMinimumWidth(tightSizeNChar(self.lblTxioInfo, 30)[0])
self.main.connect(self.main.walletsView, SIGNAL('clicked(QModelIndex)'),
updateDustLimit)
self.dustBGoneFrame = makeVertFrame([topRow, secondRow, limitPanel, self.dustTableView, 'stretch'])
# Now set the scrollarea widget to the layout
self.tabToDisplay = QScrollArea()
self.tabToDisplay.setWidgetResizable(True)
self.tabToDisplay.setWidget(self.dustBGoneFrame)
示例14: PluginUpdaterDialog
class PluginUpdaterDialog(SizePersistedDialog):
initial_extra_size = QSize(350, 100)
def __init__(self, gui, initial_filter=FILTER_UPDATE_AVAILABLE):
SizePersistedDialog.__init__(self, gui, "Plugin Updater plugin:plugin updater dialog")
self.gui = gui
self.forum_link = None
self.model = None
self.do_restart = False
self._initialize_controls()
self._create_context_menu()
display_plugins = read_available_plugins()
if display_plugins:
self.model = DisplayPluginModel(display_plugins)
self.proxy_model = DisplayPluginSortFilterModel(self)
self.proxy_model.setSourceModel(self.model)
self.plugin_view.setModel(self.proxy_model)
self.plugin_view.resizeColumnsToContents()
self.plugin_view.selectionModel().currentRowChanged.connect(self._plugin_current_changed)
self.plugin_view.doubleClicked.connect(self.install_button.click)
self.filter_combo.setCurrentIndex(initial_filter)
self._select_and_focus_view()
else:
error_dialog(
self.gui,
_("Update Check Failed"),
_("Unable to reach the MobileRead plugins forum index page."),
det_msg=MR_INDEX_URL,
show=True,
)
self.filter_combo.setEnabled(False)
# Cause our dialog size to be restored from prefs or created on first usage
self.resize_dialog()
def _initialize_controls(self):
self.setWindowTitle(_("User plugins"))
self.setWindowIcon(QIcon(I("plugins/plugin_updater.png")))
layout = QVBoxLayout(self)
self.setLayout(layout)
title_layout = ImageTitleLayout(self, "plugins/plugin_updater.png", _("User Plugins"))
layout.addLayout(title_layout)
header_layout = QHBoxLayout()
layout.addLayout(header_layout)
self.filter_combo = PluginFilterComboBox(self)
self.filter_combo.setMinimumContentsLength(20)
self.filter_combo.currentIndexChanged[int].connect(self._filter_combo_changed)
header_layout.addWidget(QLabel(_("Filter list of plugins") + ":", self))
header_layout.addWidget(self.filter_combo)
header_layout.addStretch(10)
self.plugin_view = QTableView(self)
self.plugin_view.horizontalHeader().setStretchLastSection(True)
self.plugin_view.setSelectionBehavior(QAbstractItemView.SelectRows)
self.plugin_view.setSelectionMode(QAbstractItemView.SingleSelection)
self.plugin_view.setAlternatingRowColors(True)
self.plugin_view.setSortingEnabled(True)
self.plugin_view.setIconSize(QSize(28, 28))
layout.addWidget(self.plugin_view)
details_layout = QHBoxLayout()
layout.addLayout(details_layout)
forum_label = QLabel('<a href="http://www.foo.com/">Plugin Forum Thread</a>', self)
forum_label.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard)
forum_label.linkActivated.connect(self._forum_label_activated)
details_layout.addWidget(QLabel(_("Description") + ":", self), 0, Qt.AlignLeft)
details_layout.addWidget(forum_label, 1, Qt.AlignRight)
self.description = QLabel(self)
self.description.setFrameStyle(QFrame.Panel | QFrame.Sunken)
self.description.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.description.setMinimumHeight(40)
self.description.setWordWrap(True)
layout.addWidget(self.description)
self.button_box = QDialogButtonBox(QDialogButtonBox.Close)
self.button_box.rejected.connect(self.reject)
self.finished.connect(self._finished)
self.install_button = self.button_box.addButton(_("&Install"), QDialogButtonBox.AcceptRole)
self.install_button.setToolTip(_("Install the selected plugin"))
self.install_button.clicked.connect(self._install_clicked)
self.install_button.setEnabled(False)
self.configure_button = self.button_box.addButton(
" " + _("&Customize plugin ") + " ", QDialogButtonBox.ResetRole
)
self.configure_button.setToolTip(_("Customize the options for this plugin"))
self.configure_button.clicked.connect(self._configure_clicked)
self.configure_button.setEnabled(False)
layout.addWidget(self.button_box)
def _create_context_menu(self):
self.plugin_view.setContextMenuPolicy(Qt.ActionsContextMenu)
self.install_action = QAction(QIcon(I("plugins/plugin_upgrade_ok.png")), _("&Install"), self)
self.install_action.setToolTip(_("Install the selected plugin"))
self.install_action.triggered.connect(self._install_clicked)
self.install_action.setEnabled(False)
self.plugin_view.addAction(self.install_action)
#.........这里部分代码省略.........
示例15: __init__
def __init__(self, parent=None):
QTableView.__init__(self, parent)
self.setSortingEnabled(True), self.setShowGrid(False), self.setAlternatingRowColors(True)
self.setSelectionBehavior(self.SelectRows)
self.setTabKeyNavigation(False)
self.verticalHeader().close()