Qt QInputDialog简单使用

文章目录[隐藏]

前言

主要实现了简单的QInputDialog弹出框的使用以及弹出框按钮中文适应。怕忘记留下备用。

普通用法-默认按钮

QString newName = QInputDialog::getText(NULL, QStringLiteral("修改提示"),
                                        QStringLiteral("新图例名称:"),
                                        QLineEdit::Normal,
                                        m_cntLegendItem->plottable()->name(), &ok);
qDebug() << "[" << __FUNCTION__ <<__LINE__ << "] :" <<  ok << newName;

其他用法-弹出框按钮中文显示

bool ok;
QInputDialog inputDialog;
inputDialog.setOkButtonText(QStringLiteral("确定"));
inputDialog.setCancelButtonText(QStringLiteral("取消"));
inputDialog.setWindowTitle(QStringLiteral("修改比例尺提示"));
inputDialog.setLabelText(QStringLiteral("比例尺间隔:"));
inputDialog.setTextEchoMode(QLineEdit::Normal);
inputDialog.setTextValue(QString("%1").arg( m_xMaxRange/10));
ok = inputDialog.exec();

QString space = inputDialog.textValue();

if (ok)
{
    m_xMaxRange = space.toInt() * 10;
    m_plot->xAxis->setRange(0, m_xMaxRange);
    m_plot->replot();
}

展示效果

Qt QInputDialog简单使用
posted @ 2020-05-13 20:54  不随。  阅读(172)  评论(0编辑  收藏  举报  来源