修复点击航点信息表格程序崩溃bug
This commit is contained in:
+39
-10
@@ -19,6 +19,14 @@ MissionUI::MissionUI(QWidget *parent) :
|
||||
|
||||
this->setWhatsThis(tr("mission table"));
|
||||
|
||||
tablelist.insert(1,ui->tableWidget_1);
|
||||
tablelist.insert(3,ui->tableWidget_3);
|
||||
tablelist.insert(4,ui->tableWidget_4);
|
||||
tablelist.insert(5,ui->tableWidget_5);
|
||||
tablelist.insert(6,ui->tableWidget_6);
|
||||
|
||||
ui->tabWidget->setCurrentIndex(1);
|
||||
|
||||
ui->label_Notice->adjustSize();
|
||||
ui->label_Notice->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
ui->label_Notice->setWordWrap(true);
|
||||
@@ -322,13 +330,7 @@ MissionUI::MissionUI(QWidget *parent) :
|
||||
});
|
||||
|
||||
|
||||
tablelist.insert(1,ui->tableWidget_1);
|
||||
tablelist.insert(3,ui->tableWidget_3);
|
||||
tablelist.insert(4,ui->tableWidget_4);
|
||||
tablelist.insert(5,ui->tableWidget_5);
|
||||
tablelist.insert(6,ui->tableWidget_6);
|
||||
|
||||
ui->tabWidget->setCurrentIndex(1);
|
||||
|
||||
foreach (QTableWidget *table, tablelist.values() ) {
|
||||
if(table)
|
||||
@@ -546,6 +548,24 @@ void MissionUI::resizeEvent(QResizeEvent *event)
|
||||
|
||||
}
|
||||
|
||||
bool MissionUI::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::FocusOut) //如果comboBox失去焦点就删除
|
||||
{
|
||||
|
||||
QComboBox *com_box = qobject_cast<QComboBox*>(obj);
|
||||
if(com_box && !com_box->view()->hasFocus() )
|
||||
{
|
||||
// qDebug() << u8"comboBox失去焦点";
|
||||
// com_box->deleteLater(); //删除
|
||||
emit comboBoxFocusOut(); //发出信号删除
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void MissionUI::clearTable()
|
||||
{
|
||||
|
||||
@@ -921,7 +941,7 @@ void MissionUI::pointCreate(float param1,float param2,float param3,float param4,
|
||||
{
|
||||
QTableWidget *tableWidget;
|
||||
|
||||
foreach (QTableWidget *table, tablelist) {
|
||||
foreach (QTableWidget *table, tablelist.values() ) {
|
||||
if(table)
|
||||
{
|
||||
if(tablelist.value(mission_type) == table)
|
||||
@@ -933,9 +953,10 @@ void MissionUI::pointCreate(float param1,float param2,float param3,float param4,
|
||||
}
|
||||
|
||||
int idx = seq -1;
|
||||
qDebug() << u8"组别:" << mission_type;
|
||||
|
||||
tableWidget->setRowCount(tableWidget->rowCount()+1); //设置行数+1
|
||||
tableWidget->setItem(idx,0,new QTableWidgetItem(QString::number(seq))); //第一列的内容设置为index
|
||||
tableWidget->setItem(idx,0,new QTableWidgetItem(QString::number(seq) ) ); //第一列的内容设置为index
|
||||
|
||||
QString cmdName;
|
||||
|
||||
@@ -1666,6 +1687,7 @@ void MissionUI::itemDoubleClicked(QTableWidgetItem *item)
|
||||
if(column == 1)
|
||||
{
|
||||
QComboBox *combox = new QComboBox(widget);
|
||||
combox->installEventFilter(this);
|
||||
|
||||
for (QMap<int,QString>::iterator i = commandtext.begin(); i != commandtext.end(); ++i)
|
||||
{
|
||||
@@ -1678,15 +1700,22 @@ void MissionUI::itemDoubleClicked(QTableWidgetItem *item)
|
||||
widget->removeCellWidget(row,column);
|
||||
widget->setCellWidget(row,column,combox);
|
||||
|
||||
connect(this, &MissionUI::comboBoxFocusOut, this, [=]
|
||||
{
|
||||
widget->removeCellWidget(row,column); //删除QComboBox
|
||||
});
|
||||
|
||||
connect(combox,&QComboBox::currentTextChanged,[=]{
|
||||
QString str = combox->currentText();
|
||||
widget->removeCellWidget(row,column);
|
||||
// widget->removeCellWidget(row,column);
|
||||
qDebug() << u8"cmmand发送信号";
|
||||
emit setCommand(str);//直接修改底层,让底层返回数据更新到界面
|
||||
});
|
||||
|
||||
connect(combox,&QComboBox::editTextChanged,[=]{
|
||||
QString str = combox->currentText();
|
||||
widget->removeCellWidget(row,column);
|
||||
// widget->removeCellWidget(row,column);
|
||||
qDebug() << u8"cmmand发送信号";
|
||||
emit setCommand(str);//直接修改底层,让底层返回数据更新到界面
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,6 +85,13 @@ public slots:
|
||||
protected slots:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
/**
|
||||
* @brief 事件过滤器,用来处理航点参数cmmand的combobox失去焦点后自动删除
|
||||
* @param obj
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
|
||||
private slots:
|
||||
@@ -94,6 +101,10 @@ private slots:
|
||||
void itemDoubleClicked(QTableWidgetItem *item);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief 表格中QComboBox失去焦点,发出信号
|
||||
*/
|
||||
void comboBoxFocusOut();
|
||||
|
||||
void setCommand(QVariant value);
|
||||
void setParam1(QVariant value);
|
||||
|
||||
Reference in New Issue
Block a user