本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.geometry方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.geometry方法的具體用法?Python QLineEdit.geometry怎麽用?Python QLineEdit.geometry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.geometry方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Header
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import geometry [as 別名]
class Header(QHeaderView):
def __init__(self, orientation=Qt.Horizontal, parent=None):
super(Header, self).__init__(orientation, parent)
self.editable = True
self.setSectionsClickable(True)
self.setSectionResizeMode(QHeaderView.ResizeToContents)
self.line = QLineEdit(parent=self.viewport())
self.line.setAlignment(Qt.AlignTop)
self.line.setHidden(True)
self.line.blockSignals(True)
self.col = 0
# Connections
self.sectionDoubleClicked[int].connect(self.__edit)
self.line.editingFinished.connect(self.__done_editing)
def __edit(self, index):
if not self.editable:
return
geo = self.line.geometry()
geo.setWidth(self.sectionSize(index))
geo.moveLeft(self.sectionViewportPosition(index))
current_text = self.model().headerData(index, Qt.Horizontal,
Qt.DisplayRole)
self.line.setGeometry(geo)
self.line.setHidden(False)
self.line.blockSignals(False)
self.line.setText(str(current_text))
self.line.setFocus()
self.line.selectAll()
self.col = index
def __done_editing(self):
text = self.line.text()
if not text.strip():
# No debe ser vacío
QMessageBox.critical(self, "Error",
self.tr("El campo no debe ser vacío"))
self.line.hide()
return
self.line.blockSignals(True)
self.line.setHidden(False)
self.model().setHeaderData(self.col, Qt.Horizontal, text,
Qt.DisplayRole)
self.line.setText("")
self.line.hide()
self.setCurrentIndex(QModelIndex())
示例2: Header
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import geometry [as 別名]
class Header(QHeaderView):
def __init__(self, orientation=Qt.Horizontal, parent=None):
super(Header, self).__init__(orientation, parent)
self.setSectionsClickable(True)
self.setSectionResizeMode(QHeaderView.ResizeToContents)
self.line = QLineEdit(parent=self.viewport())
self.line.setAlignment(Qt.AlignTop)
self.line.setHidden(True)
self.line.blockSignals(True)
self.col = 0
# Connections
self.sectionDoubleClicked[int].connect(self.__edit)
self.line.editingFinished.connect(self.__done_editing)
def __edit(self, index):
geo = self.line.geometry()
geo.setWidth(self.sectionSize(index))
geo.moveLeft(self.sectionViewportPosition(index))
current_text = self.model().headerData(index, Qt.Horizontal)
self.line.setGeometry(geo)
self.line.setHidden(False)
self.line.blockSignals(False)
self.line.setText(str(current_text))
self.line.setFocus()
self.line.selectAll()
self.col = index
def __done_editing(self):
self.line.blockSignals(True)
self.line.setHidden(False)
text = self.line.text()
self.model().setHeaderData(self.col, Qt.Horizontal, text)
self.line.setText("")
self.line.hide()
self.setCurrentIndex(QModelIndex())
示例3: DialogConnectToDataBase
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import geometry [as 別名]
class DialogConnectToDataBase(QDialog):
"""
Dialog for connecting to MySQL Database
"""
# Signals
if platform.system() == 'Darwin':
onDbConnected = pyqtSignal(str, MySqlAccess)
onDbConnectedFailed = pyqtSignal(str)
def __init__(self):
super().__init__()
self.__init_consts()
self._init_ui()
self.__set_default_values()
def __init_consts(self):
self.__LBL_USER_NAME = QLabel('UserName: ')
self.__LBL_PASSWORD = QLabel('Password: ')
self.__DIALOG_GEOMETRY = QRect(300, 300, 300, 120)
self.__LBL_IP = QLabel('IP: ')
self.__LBL_PORT = QLabel('Port: ')
self.__TITLE = 'Connect to Database'
self.__CONNECT = 'Connect'
self.__CANCEL = 'Cancel'
self.__ERR_MSG_INVALID_IP = 'Invalid IP Address: '
self.__ERR_MSG_INVALID_PORT = 'Invalid Port: '
self.__ERR_MSG_INVALID_USER = 'User name must not be empty'
self.__ERR_MSG_INVALID_PASSWD = 'Password must not be empty'
self.__DEFAULT_IP = 'localhost'
self.__DEFAULT_PORT = '8889'
self.__DEFAULT_USER = 'test'
self.__DEFAULT_PASSWD = 'test123'
self.__DELIMITER = ':'
def _init_ui(self):
vbox = QVBoxLayout()
vbox.setSpacing(5)
vbox.addLayout(self.__init_address_layout())
vbox.addLayout(self.__init_user_name_layout())
vbox.addLayout(self.__init_password_layout())
vbox.addLayout(self.__init_button_layout())
self.setLayout(vbox)
self.setWindowTitle(self.__TITLE)
self.setModal(True)
def __init_address_layout(self) -> QHBoxLayout:
hbox_addr = QHBoxLayout()
hbox_addr
self._leIpAddr = QLineEdit(self)
self._lePort = QLineEdit(self)
hbox_addr.addWidget(self.__LBL_IP)
hbox_addr.addWidget(self._leIpAddr)
hbox_addr.addWidget(self.__LBL_PORT)
hbox_addr.addWidget(self._lePort)
return hbox_addr
def __init_user_name_layout(self) -> QHBoxLayout:
hbox_user_name = QHBoxLayout()
self._leUserName = QLineEdit(self)
hbox_user_name.addWidget(self.__LBL_USER_NAME)
hbox_user_name.addWidget(self._leUserName)
return hbox_user_name
def __init_password_layout(self) -> QHBoxLayout:
hbox_passwd = QHBoxLayout()
self._lePasswd = QLineEdit(self)
self._lePasswd.setEchoMode(QLineEdit.Password)
self._lePasswd.setGeometry(self._leUserName.geometry())
self._lePasswd.move(self._lePasswd.geometry().top(),
self._leUserName.geometry().left())
hbox_passwd.addWidget(self.__LBL_PASSWORD)
hbox_passwd.addWidget(self._lePasswd)
return hbox_passwd
def __init_button_layout(self) -> QHBoxLayout:
hbox_btns = QHBoxLayout()
self._okButton = QPushButton(self.__CONNECT)
self._okButton.clicked.connect(self.connect_to_db)
self._cancelButton = QPushButton(self.__CANCEL)
self._cancelButton.clicked.connect(self.close)
hbox_btns.addWidget(self._okButton)
hbox_btns.addWidget(self._cancelButton)
return hbox_btns
def __set_default_values(self):
self._leIpAddr.setText(self.__DEFAULT_IP)
self._lePort.setText(self.__DEFAULT_PORT)
self._leUserName.setText(self.__DEFAULT_USER)
self._lePasswd.setText(self.__DEFAULT_PASSWD)
@pyqtSlot()
def connect_to_db(self):
if not self.__validate_input():
return
if platform.system() == 'Darwin':
db_access = MySqlAccess(self._leIpAddr.text(), int(self._lePort.text()))
if not db_access.connect(self._leUserName.text(), self._lePasswd.text()):
self.onDbConnectedFailed.emit(self._leIpAddr.text() +
self.__DELIMITER +
self._lePort.text())
#.........這裏部分代碼省略.........
示例4: EditableTabBar
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import geometry [as 別名]
class EditableTabBar(QTabBar):
""" Inherits: QTabBar
Implements editable label behaviour to tabs.
"""
def __init__(self, parent=None):
""" Constructor
Params: QWidget parent -> object's parent
Defines attributes:
window as arg parent
_editor as a QLineEdit object
"""
super().__init__(parent)
self.window = parent
self._editor = QLineEdit(self)
self._editor.setWindowFlags(Qt.Popup) #helps set location
self._editor.setFocusProxy(self) #determines focus handling
self._editor.editingFinished.connect(self.handleEditingFinished)
self._editor.installEventFilter(self) #allows use of overloaded function eventFilter() to handle events
def eventFilter(self, widget, event):
""" Overloaded object method
Params: QObject widget -> watched object (here: self)
QEvent event -> the event that is handled
Return: True if the event is handled
Return value of QTabBar.eventFilter() if the event is not handled (bool)
Determines editing is canceled if a click event is recorded outside of the _editor or if [esc] is pressed by hiding the _editor object.
Else, the event is passed on to the parent class.
"""
if ((event.type() == QEvent.MouseButtonPress and not self._editor.geometry().contains(event.globalPos())) or (event.type() == QEvent.KeyPress and event.key() == Qt.Key_Escape)):
self._editor.hide()
return True
return QTabBar.eventFilter(self, widget, event)
def mouseDoubleClickEvent(self, event):
""" Overloaded object method
Params: QEvent event -> the event that is handled
Return: None
Calls editTab() for the tab at which the double click event is recorded
"""
index = self.tabAt(event.pos())
if index >= 0 and self.window._styles[index]._user_style:
self.editTab(index)
def editTab(self, index):
""" Object method
Params: int index -> index of the tab to edit
Return: None
Sets the _editor's text, size and position to the tab label's and shows it.
"""
rect = self.tabRect(index)
self._editor.setFixedSize(rect.size())
self._editor.move(self.window.mapToGlobal(rect.topLeft()))
self._editor.setText(self.tabText(index))
if not self._editor.isVisible():
self._editor.show()
def handleEditingFinished(self):
""" Object method
Params: None
Return: None
Hides the _editor and sets the entered string as the new tab label.
Called at the automatic call of self._editor.editingFinished()
"""
index = self.currentIndex()
if index >= 0:
self._editor.hide()
new_name = self._editor.text()
self.window._styles.rename(index, new_name)
self.setTabText(index, new_name)