- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的目的是在两个QTreeView
之间进行拖放。例如:将项目从本地 TreeView 拖到远程 TreeView ,远程 TreeView 将接受信号并触发一个功能(例如:打印一些东西,所以我知道它成功了)。
我搜索了一些帖子,他们只是用一个QTreeView
来做,我仍然很困惑如何使用拖放。这是我的完整代码,包括 UI。
main.py
# coding=utf-8
__author__ = 'Administrator'
import os, re, sys, time, math
import ConfigParser
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from MainWindow_ui import Ui_MainWindow
import AccountDialog_ui
######## Config ini File Part#######################
def create_conf_ini(ipaddress='', username='', password='', secret='',mode="a+"):
conf = ConfigParser.ConfigParser()
conf.add_section("logininfor")
conf.set("logininfor", "ipaddress", ipaddress)
conf.set("logininfor", "username", username)
conf.set("logininfor", "password", password)
conf.set("logininfor", "secret", secret)
f = open('config.ini', mode)
conf.write(f)
f.close()
### get conf file
def get_infor_from_config():
conf = ConfigParser.ConfigParser()
if os.path.isfile('config.ini'):
conf.read("config.ini")
ipaddress = conf.get("logininfor", "ipaddress")
username = conf.get("logininfor", "username")
password = conf.get("logininfor", "password")
secret = conf.get("logininfor", "secret")
return ipaddress, username, password, secret
else:
create_conf_ini()
return '', '', '', ''
###############################
class S3MiniToolsView(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
self.actionAccount_Setting.triggered.connect(self.accountsetting_dlg)
self.init_localtreeview()
self.init_remotetreeview()
QtGui.QTreeView.connect(self.remote_Treeview, QtCore.SIGNAL('dropEvent()'), self.additem)
(ipaddress, username, password, secret) = get_infor_from_config()
self.servername_mainw.setText(ipaddress)
self.uid_mainw.setText(username)
self.accesskey_mainw.setText(password)
self.secretkey_mainw.setText(secret)
def init_localtreeview(self):
self.fileSystemModel = QFileSystemModel(self.local_Treeview)
self.fileSystemModel.setReadOnly(False)
#self.fileSystemModel.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot | QDir.Drives)
root = self.fileSystemModel.setRootPath("")
self.local_Treeview.setModel(self.fileSystemModel)
self.local_Treeview.setRootIndex(root)
self.local_Treeview.setDragDropMode(QtGui.QAbstractItemView.DragOnly)
#QtCore.QObject.connect(self.local_Treeview.selectionModel(), QtCore.SIGNAL('selectionChanged(QItemSelection, QItemSelection)'), self.test)
#self.local_Treeview.clicked[QtCore.QModelIndex].connect(self.test)
self.local_Treeview.clicked.connect(self.test)
self.local_Treeview.setDragEnabled(True)
def init_remotetreeview(self):
self.remote_Treeview.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
# self.fileSystemModel = QFileSystemModel(self.local_Treeview)
# self.fileSystemModel.setReadOnly(False)
# self.remote_Treeview.setModel(self.fileSystemModel)
self.model = QtGui.QStandardItemModel(self.remote_Treeview)
self.remote_Treeview.setModel(self.model)
self.remote_Treeview.setAcceptDrops(True)
def dragEnterEvent(self, e):
if e.mimeData().hasFormat('text/plain'):
e.accept()
else:
e.ignore()
def dropEvent(self, e):
print 'In dropEvent'
# item = QtGui.QStandardItem("did ok")
# self.model.appendRow(item)
#self.remote_Treeview.(e.mimeData().text())
def additem(self):
item = QtGui.QStandardItem("did ok")
self.model.appendRow(item)
#@QtCore.pyqtSlot("QItemSelection, QItemSelection")
@QtCore.pyqtSlot(QtCore.QModelIndex)
def test(self, index):
indexItem = self.fileSystemModel.index(index.row(), 0, index.parent())
# path or filename selected
fileName = self.fileSystemModel.fileName(indexItem)
# full path/filename selected
filePath = self.fileSystemModel.filePath(indexItem)
print("hello!")
print(fileName)
print(filePath)
def accountsetting_dlg(self):
print "AccountSetting"
accountdlg = QuickConnectDlg(self)
accountdlg.lineEdit_servername.setText( 'ceph-radosgw.lab.com')
accountdlg.lineEdit_accountname.setText( 'johndoe')
accountdlg.lineEdit_accesskey.setText( 'CIXN1L1B42JAYGV6KSIT')
accountdlg.lineEdit_secretkey.setText('17YTAqVBL60StWQniDNWoAH04bScFbjxAxpxNFCg')
accountdlg.lineEdit_httpport.setText( '8080')
accountdlg.lineEdit_httpsport.setText( '443')
if accountdlg.exec_():
servername = accountdlg.lineEdit_servername.text()
accountname = accountdlg.lineEdit_accountname.text()
accesskey = accountdlg.lineEdit_accesskey.text()
secretkey = accountdlg.lineEdit_secretkey.text()
create_conf_ini(servername, accountname, accesskey, secretkey, 'r+')
return
class QuickConnectDlg(QDialog, AccountDialog_ui.Ui_accountDialog):
def __init__(self, parent=None):
super(QuickConnectDlg, self).__init__(parent)
self.setupUi(self)
def main():
app = QApplication(sys.argv)
window = S3MiniToolsView()
window.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
这是MainWindow_ui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'MainWindow.ui'
#
# Created: Thu Aug 28 09:43:28 2014
# by: PyQt4 UI code generator 4.11.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(961, 623)
MainWindow.setInputMethodHints(QtCore.Qt.ImhNone)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setEnabled(True)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayoutWidget_3 = QtGui.QWidget(self.centralwidget)
self.verticalLayoutWidget_3.setGeometry(QtCore.QRect(20, 550, 91, 41))
self.verticalLayoutWidget_3.setObjectName(_fromUtf8("verticalLayoutWidget_3"))
self.verticalLayout_3 = QtGui.QVBoxLayout(self.verticalLayoutWidget_3)
self.verticalLayout_3.setMargin(0)
self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
self.pButton_Exportxls = QtGui.QPushButton(self.verticalLayoutWidget_3)
self.pButton_Exportxls.setObjectName(_fromUtf8("pButton_Exportxls"))
self.verticalLayout_3.addWidget(self.pButton_Exportxls)
self.label_4 = QtGui.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(0, 130, 951, 20))
self.label_4.setFrameShape(QtGui.QFrame.Box)
self.label_4.setFrameShadow(QtGui.QFrame.Sunken)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.horizontalGroupBox = QtGui.QGroupBox(self.centralwidget)
self.horizontalGroupBox.setGeometry(QtCore.QRect(0, 20, 961, 51))
self.horizontalGroupBox.setObjectName(_fromUtf8("horizontalGroupBox"))
self.horizontalLayout = QtGui.QHBoxLayout(self.horizontalGroupBox)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label_10 = QtGui.QLabel(self.horizontalGroupBox)
self.label_10.setFrameShape(QtGui.QFrame.NoFrame)
self.label_10.setFrameShadow(QtGui.QFrame.Sunken)
self.label_10.setAlignment(QtCore.Qt.AlignCenter)
self.label_10.setObjectName(_fromUtf8("label_10"))
self.horizontalLayout.addWidget(self.label_10)
self.servername_mainw = QtGui.QLineEdit(self.horizontalGroupBox)
self.servername_mainw.setObjectName(_fromUtf8("servername_mainw"))
self.horizontalLayout.addWidget(self.servername_mainw)
self.label_5 = QtGui.QLabel(self.horizontalGroupBox)
self.label_5.setFrameShape(QtGui.QFrame.NoFrame)
self.label_5.setFrameShadow(QtGui.QFrame.Sunken)
self.label_5.setAlignment(QtCore.Qt.AlignCenter)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.horizontalLayout.addWidget(self.label_5)
self.uid_mainw = QtGui.QLineEdit(self.horizontalGroupBox)
self.uid_mainw.setObjectName(_fromUtf8("uid_mainw"))
self.horizontalLayout.addWidget(self.uid_mainw)
self.label_3 = QtGui.QLabel(self.horizontalGroupBox)
self.label_3.setFrameShape(QtGui.QFrame.NoFrame)
self.label_3.setFrameShadow(QtGui.QFrame.Sunken)
self.label_3.setAlignment(QtCore.Qt.AlignCenter)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.horizontalLayout.addWidget(self.label_3)
self.accesskey_mainw = QtGui.QLineEdit(self.horizontalGroupBox)
self.accesskey_mainw.setObjectName(_fromUtf8("accesskey_mainw"))
self.horizontalLayout.addWidget(self.accesskey_mainw)
self.label_6 = QtGui.QLabel(self.horizontalGroupBox)
self.label_6.setFrameShape(QtGui.QFrame.NoFrame)
self.label_6.setFrameShadow(QtGui.QFrame.Sunken)
self.label_6.setAlignment(QtCore.Qt.AlignCenter)
self.label_6.setObjectName(_fromUtf8("label_6"))
self.horizontalLayout.addWidget(self.label_6)
self.secretkey_mainw = QtGui.QLineEdit(self.horizontalGroupBox)
self.secretkey_mainw.setInputMethodHints(QtCore.Qt.ImhHiddenText|QtCore.Qt.ImhNoAutoUppercase|QtCore.Qt.ImhNoPredictiveText|QtCore.Qt.ImhPreferNumbers)
self.secretkey_mainw.setText(_fromUtf8(""))
self.secretkey_mainw.setEchoMode(QtGui.QLineEdit.Password)
self.secretkey_mainw.setObjectName(_fromUtf8("secretkey_mainw"))
self.horizontalLayout.addWidget(self.secretkey_mainw)
spacerItem = QtGui.QSpacerItem(20, 10, QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.connect_pButton = QtGui.QPushButton(self.horizontalGroupBox)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.connect_pButton.sizePolicy().hasHeightForWidth())
self.connect_pButton.setSizePolicy(sizePolicy)
self.connect_pButton.setMinimumSize(QtCore.QSize(75, 23))
self.connect_pButton.setMaximumSize(QtCore.QSize(75, 23))
self.connect_pButton.setObjectName(_fromUtf8("connect_pButton"))
self.horizontalLayout.addWidget(self.connect_pButton)
self.filename = QtGui.QLineEdit(self.centralwidget)
self.filename.setGeometry(QtCore.QRect(190, 540, 110, 20))
self.filename.setObjectName(_fromUtf8("filename"))
self.label_7 = QtGui.QLabel(self.centralwidget)
self.label_7.setGeometry(QtCore.QRect(460, 75, 78, 16))
self.label_7.setFrameShape(QtGui.QFrame.NoFrame)
self.label_7.setFrameShadow(QtGui.QFrame.Sunken)
self.label_7.setAlignment(QtCore.Qt.AlignCenter)
self.label_7.setObjectName(_fromUtf8("label_7"))
self.buckets_cBox_mainw = QtGui.QComboBox(self.centralwidget)
self.buckets_cBox_mainw.setGeometry(QtCore.QRect(103, 100, 111, 20))
self.buckets_cBox_mainw.setObjectName(_fromUtf8("buckets_cBox_mainw"))
self.label_8 = QtGui.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(20, 100, 78, 16))
self.label_8.setFrameShape(QtGui.QFrame.NoFrame)
self.label_8.setFrameShadow(QtGui.QFrame.Sunken)
self.label_8.setAlignment(QtCore.Qt.AlignCenter)
self.label_8.setObjectName(_fromUtf8("label_8"))
self.uri_mainw = QtGui.QLineEdit(self.centralwidget)
self.uri_mainw.setGeometry(QtCore.QRect(103, 76, 261, 20))
self.uri_mainw.setObjectName(_fromUtf8("uri_mainw"))
self.label_9 = QtGui.QLabel(self.centralwidget)
self.label_9.setGeometry(QtCore.QRect(20, 80, 78, 16))
self.label_9.setFrameShape(QtGui.QFrame.NoFrame)
self.label_9.setFrameShadow(QtGui.QFrame.Sunken)
self.label_9.setAlignment(QtCore.Qt.AlignCenter)
self.label_9.setObjectName(_fromUtf8("label_9"))
self.local_Treeview = QtGui.QTreeView(self.centralwidget)
self.local_Treeview.setGeometry(QtCore.QRect(0, 160, 501, 361))
self.local_Treeview.setEditTriggers(QtGui.QAbstractItemView.DoubleClicked|QtGui.QAbstractItemView.EditKeyPressed|QtGui.QAbstractItemView.SelectedClicked)
self.local_Treeview.setDragEnabled(True)
self.local_Treeview.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
self.local_Treeview.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.local_Treeview.setObjectName(_fromUtf8("local_Treeview"))
self.remote_Treeview = QtGui.QTreeView(self.centralwidget)
self.remote_Treeview.setGeometry(QtCore.QRect(507, 160, 451, 361))
self.remote_Treeview.setEditTriggers(QtGui.QAbstractItemView.DoubleClicked|QtGui.QAbstractItemView.EditKeyPressed|QtGui.QAbstractItemView.SelectedClicked)
self.remote_Treeview.setDragDropMode(QtGui.QAbstractItemView.DropOnly)
self.remote_Treeview.setDefaultDropAction(QtCore.Qt.CopyAction)
self.remote_Treeview.setObjectName(_fromUtf8("remote_Treeview"))
self.root_cBox_mainw = QtGui.QComboBox(self.centralwidget)
self.root_cBox_mainw.setGeometry(QtCore.QRect(536, 70, 141, 20))
self.root_cBox_mainw.setObjectName(_fromUtf8("root_cBox_mainw"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 961, 17))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menuW = QtGui.QMenu(self.menubar)
self.menuW.setObjectName(_fromUtf8("menuW"))
self.menu = QtGui.QMenu(self.menubar)
self.menu.setObjectName(_fromUtf8("menu"))
self.menuTools = QtGui.QMenu(self.menubar)
self.menuTools.setObjectName(_fromUtf8("menuTools"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.actionOpenfile = QtGui.QAction(MainWindow)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("../Gui-test/Resource/OpenFile.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionOpenfile.setIcon(icon)
self.actionOpenfile.setObjectName(_fromUtf8("actionOpenfile"))
self.actionAccount_Setting = QtGui.QAction(MainWindow)
self.actionAccount_Setting.setObjectName(_fromUtf8("actionAccount_Setting"))
self.menuW.addAction(self.actionOpenfile)
self.menuTools.addAction(self.actionAccount_Setting)
self.menubar.addAction(self.menuW.menuAction())
self.menubar.addAction(self.menuTools.menuAction())
self.menubar.addAction(self.menu.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.uid_mainw, self.accesskey_mainw)
MainWindow.setTabOrder(self.accesskey_mainw, self.secretkey_mainw)
MainWindow.setTabOrder(self.secretkey_mainw, self.connect_pButton)
MainWindow.setTabOrder(self.connect_pButton, self.pButton_Exportxls)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "mini S3 File Manager", None))
self.pButton_Exportxls.setText(_translate("MainWindow", "导出到xls", None))
self.label_4.setText(_translate("MainWindow", "Detail Information:", None))
self.horizontalGroupBox.setTitle(_translate("MainWindow", "S3 Storage Account Information:", None))
self.label_10.setText(_translate("MainWindow", "Server:", None))
self.servername_mainw.setToolTip(_translate("MainWindow", "需要检查的设备IP", None))
self.label_5.setText(_translate("MainWindow", "Account name:", None))
self.uid_mainw.setToolTip(_translate("MainWindow", "需要检查的设备IP", None))
self.label_3.setText(_translate("MainWindow", "Access key:", None))
self.label_6.setText(_translate("MainWindow", "Secret key:", None))
self.connect_pButton.setToolTip(_translate("MainWindow", "开始检查", None))
self.connect_pButton.setText(_translate("MainWindow", "Connect", None))
self.label_7.setText(_translate("MainWindow", "Root:", None))
self.label_8.setText(_translate("MainWindow", "My Buckets:", None))
self.label_9.setText(_translate("MainWindow", "URI:", None))
self.menuW.setTitle(_translate("MainWindow", "文件", None))
self.menu.setTitle(_translate("MainWindow", "帮助", None))
self.menuTools.setTitle(_translate("MainWindow", "Tools", None))
self.actionOpenfile.setText(_translate("MainWindow", "Openfile", None))
self.actionAccount_Setting.setText(_translate("MainWindow", "Account Setting", None))
AccountDialog_ui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'AccountDialog.ui'
#
# Created: Mon Aug 25 23:41:07 2014
# by: PyQt4 UI code generator 4.11.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_accountDialog(object):
def setupUi(self, accountDialog):
accountDialog.setObjectName(_fromUtf8("accountDialog"))
accountDialog.resize(400, 248)
self.layoutWidget = QtGui.QWidget(accountDialog)
self.layoutWidget.setGeometry(QtCore.QRect(10, 10, 380, 225))
self.layoutWidget.setObjectName(_fromUtf8("layoutWidget"))
self.gridLayout_3 = QtGui.QGridLayout(self.layoutWidget)
self.gridLayout_3.setMargin(0)
self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3"))
self.tabWidget_2 = QtGui.QTabWidget(self.layoutWidget)
self.tabWidget_2.setObjectName(_fromUtf8("tabWidget_2"))
self.tabWidgetPage1_2 = QtGui.QWidget()
self.tabWidgetPage1_2.setObjectName(_fromUtf8("tabWidgetPage1_2"))
self.gridLayout_4 = QtGui.QGridLayout(self.tabWidgetPage1_2)
self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4"))
self.label_7 = QtGui.QLabel(self.tabWidgetPage1_2)
self.label_7.setObjectName(_fromUtf8("label_7"))
self.gridLayout_4.addWidget(self.label_7, 0, 0, 1, 1)
self.lineEdit_servername = QtGui.QLineEdit(self.tabWidgetPage1_2)
self.lineEdit_servername.setObjectName(_fromUtf8("lineEdit_servername"))
self.gridLayout_4.addWidget(self.lineEdit_servername, 0, 1, 1, 2)
self.label_8 = QtGui.QLabel(self.tabWidgetPage1_2)
self.label_8.setObjectName(_fromUtf8("label_8"))
self.gridLayout_4.addWidget(self.label_8, 1, 0, 1, 1)
self.lineEdit_accountname = QtGui.QLineEdit(self.tabWidgetPage1_2)
self.lineEdit_accountname.setObjectName(_fromUtf8("lineEdit_accountname"))
self.gridLayout_4.addWidget(self.lineEdit_accountname, 1, 1, 1, 2)
self.label_9 = QtGui.QLabel(self.tabWidgetPage1_2)
self.label_9.setObjectName(_fromUtf8("label_9"))
self.gridLayout_4.addWidget(self.label_9, 2, 0, 1, 1)
self.lineEdit_accesskey = QtGui.QLineEdit(self.tabWidgetPage1_2)
self.lineEdit_accesskey.setObjectName(_fromUtf8("lineEdit_accesskey"))
self.gridLayout_4.addWidget(self.lineEdit_accesskey, 2, 1, 1, 2)
self.label_10 = QtGui.QLabel(self.tabWidgetPage1_2)
self.label_10.setObjectName(_fromUtf8("label_10"))
self.gridLayout_4.addWidget(self.label_10, 3, 0, 1, 1)
self.lineEdit_secretkey = QtGui.QLineEdit(self.tabWidgetPage1_2)
self.lineEdit_secretkey.setObjectName(_fromUtf8("lineEdit_secretkey"))
self.gridLayout_4.addWidget(self.lineEdit_secretkey, 3, 1, 1, 2)
self.label_11 = QtGui.QLabel(self.tabWidgetPage1_2)
self.label_11.setObjectName(_fromUtf8("label_11"))
self.gridLayout_4.addWidget(self.label_11, 4, 0, 1, 1)
self.lineEdit_httpport = QtGui.QLineEdit(self.tabWidgetPage1_2)
self.lineEdit_httpport.setObjectName(_fromUtf8("lineEdit_httpport"))
self.gridLayout_4.addWidget(self.lineEdit_httpport, 4, 1, 1, 1)
self.label_12 = QtGui.QLabel(self.tabWidgetPage1_2)
self.label_12.setObjectName(_fromUtf8("label_12"))
self.gridLayout_4.addWidget(self.label_12, 5, 0, 1, 1)
self.lineEdit_httpsport = QtGui.QLineEdit(self.tabWidgetPage1_2)
self.lineEdit_httpsport.setObjectName(_fromUtf8("lineEdit_httpsport"))
self.gridLayout_4.addWidget(self.lineEdit_httpsport, 5, 1, 1, 1)
self.checkBox_https = QtGui.QCheckBox(self.tabWidgetPage1_2)
self.checkBox_https.setObjectName(_fromUtf8("checkBox_https"))
self.gridLayout_4.addWidget(self.checkBox_https, 5, 2, 1, 1)
self.tabWidget_2.addTab(self.tabWidgetPage1_2, _fromUtf8(""))
self.gridLayout_3.addWidget(self.tabWidget_2, 0, 0, 1, 3)
spacerItem = QtGui.QSpacerItem(218, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_3.addItem(spacerItem, 1, 0, 1, 1)
self.buttonBox = QtGui.QDialogButtonBox(self.layoutWidget)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.gridLayout_3.addWidget(self.buttonBox, 1, 1, 1, 1)
self.retranslateUi(accountDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), accountDialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), accountDialog.reject)
QtCore.QMetaObject.connectSlotsByName(accountDialog)
def retranslateUi(self, accountDialog):
accountDialog.setWindowTitle(_translate("accountDialog", "Account", None))
self.label_7.setText(_translate("accountDialog", "Server name", None))
self.label_8.setText(_translate("accountDialog", "Account name", None))
self.label_9.setText(_translate("accountDialog", "Access key", None))
self.label_10.setText(_translate("accountDialog", "Secret key", None))
self.label_11.setText(_translate("accountDialog", "HTTP Port", None))
self.lineEdit_httpport.setText(_translate("accountDialog", "8080", None))
self.label_12.setText(_translate("accountDialog", "HTTPS Port", None))
self.lineEdit_httpsport.setText(_translate("accountDialog", "443", None))
self.checkBox_https.setText(_translate("accountDialog", "Connect usring SSL/HTTPS", None))
self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tabWidgetPage1_2), _translate("accountDialog", "Account", None))
最佳答案
如果您在2个小部件之间交换数据,我建议使用QTreeWidget
而不是QTreeView
,因为QTreeWidget
中的数据可以编辑动态数据,行和值(value)。在 2 个 QTreeWidget
之间拖放时,我们可以将它们等效为“复制和删除”。
很容易在2个QTreeWidget
之间实现,您只需在QTreeWidget
中拖动输入事件并复制到新的QTreeWidget
时进行处理。 (如果您内部移动,我将自行删除旧数据)接下来,如果QTreeWidget
之间有移动数据,请创建您自己的信号来处理它们。最后,将其集成到您的类或小部件中。
示例(不是您的代码,但您可以自己实现),像这样;
import sys
from PyQt4 import QtCore, QtGui
class QCustomTreeWidget (QtGui.QTreeWidget):
itemMoveOutActivated = QtCore.pyqtSignal(object)
itemNewMoveActivated = QtCore.pyqtSignal(object)
def __init__ (self, parent = None):
super(QCustomTreeWidget, self).__init__(parent)
self.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
def dragEnterEvent (self, eventQDragEnterEvent):
sourceQCustomTreeWidget = eventQDragEnterEvent.source()
if isinstance(sourceQCustomTreeWidget, QCustomTreeWidget) and (self is not sourceQCustomTreeWidget):
eventQDragEnterEvent.accept()
else:
QtGui.QTreeWidget.dragEnterEvent(self, eventQDragEnterEvent)
def dropEvent (self, eventQDropEvent):
sourceQCustomTreeWidget = eventQDropEvent.source()
if isinstance(sourceQCustomTreeWidget, QCustomTreeWidget) and (self is not sourceQCustomTreeWidget):
sourceQTreeWidgetItem = sourceQCustomTreeWidget.currentItem()
destinationQTreeWidgetItem = sourceQTreeWidgetItem.clone()
self.addTopLevelItem(destinationQTreeWidgetItem)
sourceQCustomTreeWidget.itemMoveOutActivated.emit(destinationQTreeWidgetItem)
self.itemNewMoveActivated.emit(destinationQTreeWidgetItem)
else:
QtGui.QTreeWidget.dropEvent(self, eventQDropEvent)
class QCustomQWidget (QtGui.QWidget):
def __init__ (self, parent = None):
super(QCustomQWidget, self).__init__(parent)
self.my1QCustomTreeWidget = QCustomTreeWidget(self)
self.my2QCustomTreeWidget = QCustomTreeWidget(self)
self.my1QCustomTreeWidget.itemMoveOutActivated.connect(self.itemMoveOutActivatedCallBack1)
self.my2QCustomTreeWidget.itemMoveOutActivated.connect(self.itemMoveOutActivatedCallBack2)
self.my1QCustomTreeWidget.itemNewMoveActivated.connect(self.itemNewMoveActivatedCallBack1)
self.my2QCustomTreeWidget.itemNewMoveActivated.connect(self.itemNewMoveActivatedCallBack2)
listsExampleQTreeWidgetItem = [QtGui.QTreeWidgetItem([name]) for name in ['Part A', 'Part B', 'Part C']]
self.my1QCustomTreeWidget.addTopLevelItems(listsExampleQTreeWidgetItem)
self.allQHBoxLayout = QtGui.QHBoxLayout()
self.allQHBoxLayout.addWidget(self.my1QCustomTreeWidget)
self.allQHBoxLayout.addWidget(self.my2QCustomTreeWidget)
self.setLayout(self.allQHBoxLayout)
@QtCore.pyqtSlot(QtGui.QTreeWidgetItem)
def itemMoveOutActivatedCallBack1 (self, goneQTreeWidgetItem):
print 'QTreeWidget 1 has move QTreeWidgetItem to Another QTreeWidget'
@QtCore.pyqtSlot(QtGui.QTreeWidgetItem)
def itemMoveOutActivatedCallBack2 (self, goneQTreeWidgetItem):
print 'QTreeWidget 2 has move QTreeWidgetItem to Another QTreeWidget'
@QtCore.pyqtSlot(QtGui.QTreeWidgetItem)
def itemNewMoveActivatedCallBack1 (self, newQTreeWidgetItem):
print 'Another QTreeWidget has move QTreeWidgetItem in QTreeWidget 1'
@QtCore.pyqtSlot(QtGui.QTreeWidgetItem)
def itemNewMoveActivatedCallBack2 (self, newQTreeWidgetItem):
print 'Another QTreeWidget has move QTreeWidgetItem in QTreeWidget 2'
app = QtGui.QApplication(sys.argv)
myQCustomQWidget = QCustomQWidget()
myQCustomQWidget.show()
sys.exit(app.exec_())
希望是有帮助的,
关于python - 在两个 QTreeView 之间拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25540028/
这个问题在这里已经有了答案: Difference between Property and Field in C# 3.0+ (10 个答案) 关闭 10 年前。 我不明白静态属性之间的区别: p
当元素被拖放时,有没有办法从被拖动的元素中获取 id(或其他属性值)? 例如,在左侧,我有一堆 div,我可以将图像放入其中。右边有一个 div 用来保存图像。当我将图像从右侧拖动到左侧的 div 时
每当我更改其中一个类属性时,我想设置一个修改标志,如下所示 public bool Modified { get; set; } public bool Enabled { get; set { Mo
由于某种原因,我下面的代码曾经可以正常工作,但现在却引发了一个异常: public static async Task HttpPut(string inUrl, string inFilePath)
为什么将 ; 放在最佳实践中?在函数定义的末尾。 例如 var tony = function () { console.log("hello there"); }; 优于: var tony
我在容器内有一个位图。当我拖动容器时,光标变为编辑文本形状,图像也跳到光标的右下角(好像我从左上角拿着图像并拖动它)。 这是我的代码,所以你可以看到我有 RTFM: function createIc
这个问题已经有答案了: C# 3.0 auto-properties — useful or not? [closed] (17 个回答) 已关闭 6 年前。 当我让 Visual Studio 20
以类中的以下代码为例: public class Employee : IEntity { public string FirstName { get; set; } public s
我有 json 数据: { "products": [ { "productId" : 0, "productImg" : "../img/product-ph
这个问题在这里已经有了答案: What is the difference between a field and a property? (33 个答案) 关闭 9 年前。 我在一本书上找到这样声
我正在设置多个方法,想知道如何继续将一个变量(“顶部”变量)传递给不同的方法。 主要方法: public static void Main(string[] args) { i
我正在尝试使用 crontab 编写一个简单的任务,将一些文件从本地复制到 HDFS。我的代码是这样的: #!/bing/ksh ANIO=$(date +"%Y") MES=$(date +"%m"
有人可以告诉我如何使用这个解决方案来解决我的问题吗?我也想限制 id 中包含文本“not”的节点的拖/放。 jsTree drag and drop restrict folders by class
我的情况如下 - 我正在对可能包含链接行的表进行排序: row 1 row 2 row 3 row 4 row 5 我需要的是禁止在.linked-to-p
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我在理解似乎不一致的方案中的破坏性操作时遇到问题。即为什么下例中bar没有变化 (define foo '(a b)) (define bar foo) (set! foo '(c d)) foo >
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我在理解似乎不一致的方案中的破坏性操作时遇到问题。即为什么下例中bar没有变化 (define foo '(a b)) (define bar foo) (set! foo '(c d)) foo >
我在我的 Web 应用程序中使用 Ajax ControlToolkit 中的 ModalPopupExtender。我将其 Drag 属性设置为 true,但是当我拖动弹出面板并将其放到新位置时,它
所以,基于this answer ,我有一组可以拖放并卡入到位的 div。唯一的问题是,可拖动的 div 具有不同的高度,我需要它们始终捕捉到目标的底部,而不是顶部。 您可以在this JsFiddl
我是一名优秀的程序员,十分优秀!