PyQt 中是否有某种方法可以获取所有QLineEdit
对象的集合?
我正在尝试添加一个重置按钮,它将清除QLineEdit
表单上的所有文本,因此我正在寻找一种方法来循环遍历所有QLineEdit
对象,而不是将它们全部列在将连接到重置按钮的重置函数中。
谢谢你。
我想转换QString
为quint16
.我正在从a读取端口号textBox
,我需要将其转换quint16
为我的UDP
socket writeData()
函数的格式.
是否更容易将文本存储在QByteArray
然后转换它?如果是这样,我只找到了修饰符toUint()
,但没有找到quint16
.
有一个QTableView()
,其中一列填充了QComboBox
es。问题是如何QTableView()
根据字典中的数据选择组合框中的项目
我知道我应该申请,self.combo.setCurrentIndex(self.combo.findText( status_str))
但无法理解如何将该变量status_str
放入comboBox
或放置在代码中应用它的位置。我也无法理解 makecomboBox
只有在双击后才会出现。如果没有双击单元格,它必须看起来像任何其他单元格。
代码示例:
data = {"first":{"status":"closed"},"second":{"status":"expired"},"third":{ "status":"cancelled"}}
class ComboDelegate(QItemDelegate):
def __init__(self, parent):
QItemDelegate.__init__(self, parent)
def paint(self, painter, option, index):
self.combo = QComboBox(self.parent())
li = []
li.append("closed")
li.append("expired")
li.append("cancelled")
li.append("waiting")
self.combo.addItems(li)
#self.combo.setCurrentIndex(self.combo.findText( status_str ))
if not self.parent().indexWidget(index):
self.parent().setIndexWidget( index, self.combo )
class TableView(QTableView):
def __init__(self, *args, **kwargs):
QTableView.__init__(self, *args, **kwargs)
self.setItemDelegateForColumn(1, ComboDelegate(self))
class MainFrame(QWidget):
def __init__(self):
QWidget.__init__(self)
table = TableView(self)
self.model = QStandardItemModel()
table.setModel(self.model)
MainWindow …
Run Code Online (Sandbox Code Playgroud) 我有一个指向其他对象的指针数组Comparable* array
(在类的模板中).
我理解delete
删除指针引用的内存,并delete []
释放分配给数组中每个指针的内存.
我的问题是,如果我有一个包含指向其他对象的指针的数组,如何释放数组中每个指针和数组本身引用的内存?
我正在尝试使用ON DELETE CASCADE
我正在处理的数据库.似乎没有工作,所以我在一个简单的例子上测试了它没有成功.
CREATE TABLE foo (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
data VARCHAR(10),
PRIMARY KEY (id)
)ENGINE=InnoDB;
CREATE TABLE foo2 (
id INT UNSIGNED NOT NULL,
data2 VARCHAR(10),
PRIMARY KEY (id),
CONSTRAINT fk_foo2_id FOREIGN KEY (id) REFERENCES foo(id) ON DELETE CASCADE
)ENGINE=InnoDB;
INSERT INTO foo (data) VALUE ('hello'),('world'),('mysql');
INSERT INTO foo2 (data2) VALUE ('hello2'),('world2'),('mysql2');
SELECT * FROM foo;
+----+-------+
| id | data |
+----+-------+
| 1 | hello |
| 2 | world |
| …
Run Code Online (Sandbox Code Playgroud) 当我通过qInstallMessageHandler
函数实现我的自定义日志处理程序时,调试日志中的俄语文本有问题。目前,我的代码是:
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
QByteArray localMsg = msg.toLatin1();
QString stringType;
switch (type) {
case QtDebugMsg:
stringType = "D";
break;
case QtWarningMsg:
stringType = "W";
break;
case QtCriticalMsg:
stringType = "C";
break;
case QtFatalMsg:
stringType = "Fatal";
break;
default:
stringType = "Unknown";
}
QString logString = QString("[%1] %2:%3 - %4\n")
.arg(stringType)
.arg(context.function)
.arg(context.line)
.arg(localMsg.constData());
if (__logFile.isOpen()) {
QTextStream stream(&__logFile);
stream << logString;
}
QTextStream stderrStream(stderr, QIODevice::WriteOnly);
stderrStream<<logString;
if (type == QtFatalMsg) { …
Run Code Online (Sandbox Code Playgroud) 我希望有多次使用自动完成者在我的可能性QLineEdit
,我发现例如使用QTextEdit
,但我找不到QLineEdit
。这是我使用的一段代码(非常简单):
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import sys
def main():
app = QApplication(sys.argv)
edit = QLineEdit()
strList = ["Germany", "Spain", "France", "Norway"]
completer = QCompleter(strList,edit)
edit.setCompleter(completer)
edit.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
例如,QLineEdit
如果我添加逗号,我希望完成者再次“开始预测”相同的单词。谢谢。
我有一个文本列表,如果用户在 中搜索文本QLineEdit
,我会打印该文本。有一个QCompleter
在QLineEdit
。
问题是,正如我们所知Text
,text
它们并不相同,但对用户来说是相同的。因此,如果用户开始打字Text
或者text
,我想将其更改为TEXT
实时QLineEdit
。因此,每当用户键入字母时,我都希望在QCompleter
-中将其设为大写QLineEdit
。我怎样才能做到这一点?我有这个自动取款机;
from PyQt5.QtWidgets import QApplication,QPushButton,QMainWindow,QLabel,QLineEdit,QCompleter
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import QPoint
import sys
class cssden(QMainWindow):
def __init__(self):
super().__init__()
self.mwidget = QMainWindow(self)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
#size
self.setFixedSize(600,400)
#LINE EDIT QCOMPLETER
self.label = QLineEdit(self)
self.label.setGeometry(100,100,300,30)
self.label.setStyleSheet("color: red;"
"font: bold 15pt 'Arial';")
self.t = ["Hello","hi","Hey"]
self.label.setCompleter(QCompleter(self.t, self))
#BUTTON
self.buton = QPushButton(self)
self.buton.setText("Click")
self.buton.setGeometry(200,140,90,50)
self.buton.clicked.connect(self.hangiButon)
#SET LABEL
self.set_label …
Run Code Online (Sandbox Code Playgroud) 我不知道为什么会发生这种情况.我已经扩展QObject
并添加了宏Q_OBJECT
.信号和插槽也有相同的参数.
我已经发布了原始问题
这是我的hpp文件:
/*
* LocationMonitor.hpp
*
* Created on: Jul 13, 2013
* Author: Roland
*/
#ifndef LOCATIONMONITOR_HPP_
#define LOCATIONMONITOR_HPP_
#include <QObject>
#include <QtLocationSubset/qgeopositioninfo.h>
#include <QtLocationSubset/qgeoareamonitor.h>
using namespace Qt;
using namespace QtMobilitySubset;
class GeoNotification;
class LocationMonitor : public QObject
{
Q_OBJECT
public:
LocationMonitor(int id,GeoNotification *geoNotification,QVariantList locationList,QVariantList actionList);
virtual ~LocationMonitor();
public slots:
void areaEnteredd(QtMobilitySubset::QGeoPositionInfo info);
void areaExitedd(QtMobilitySubset::QGeoPositionInfo info);
public:
QGeoAreaMonitor *monitor;
};
#endif /* LOCATIONMONITOR_HPP_ */
Run Code Online (Sandbox Code Playgroud)
这是我的cpp文件
/*
* LocationMonitor.cpp
*
* Created on: Jul …
Run Code Online (Sandbox Code Playgroud)