写一个简单的小弹窗

直接上代码

#include <QDialog>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLineEdit>

class FileOpenDialog : public QDialog
{
    Q_OBJECT

public:
    explicit FileOpenDialog(QWidget *parent = nullptr);

private slots:
    void openStpFile();
    void openAedtFile();

private:
    QPushButton *openStepButton{nullptr};
    QPushButton *openAedtButton{nullptr};
    QLineEdit * stepPathLine_ {nullptr};
    QLineEdit * aedtPathLine_ {nullptr};

};

cpp 文件

#include <QFileDialog>
#include <QDebug>
#include <QLabel>

namespace {
const size_t STEP_LINE_LENGTH = 80;
const size_t AEDT_LINE_LENGTH = 80;
const size_t STEP_LABEL_LENGTH = 80;
const size_t AEDT_LABEL_LENGTH = 80;
}
FileOpenDialog::FileOpenDialog(QWidget *parent) :
    QDialog(parent)
{
    // 创建按钮
    openStepButton = new QPushButton("Open .stp .step File", this);
    openAedtButton = new QPushButton("Open .aedt File", this);

    stepPathLine_  = new QLineEdit;
    stepPathLine_->setFixedWidth(STEP_LINE_LENGTH);
    aedtPathLine_ = new QLineEdit;
    aedtPathLine_->setFixedWidth(AEDT_LINE_LENGTH);
    QLabel * stepLabel = new QLabel("Open .stp .step File",this);
    stepLabel->setMinimumWidth(STEP_LABEL_LENGTH);
    QLabel * aedtLabel = new QLabel("Open .aedt File",this);
    aedtLabel->setMinimumWidth(AEDT_LABEL_LENGTH);

    // 创建布局
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    QHBoxLayout *stpLayout = new QHBoxLayout();
    QHBoxLayout *aedtLayout = new QHBoxLayout();

    // 添加按钮到布局
    stpLayout->addWidget(stepLabel);
    stpLayout->addWidget(stepPathLine_);
    stpLayout->addWidget(openStepButton);

    aedtLayout->addWidget(aedtLabel);
    aedtLayout->addWidget(aedtPathLine_);
    aedtLayout->addWidget(openAedtButton);

    mainLayout->addLayout(stpLayout);
    mainLayout->addLayout(aedtLayout);

    setLayout(mainLayout);

    // 连接按钮点击事件到对应的槽函数
    connect(openStepButton, &QPushButton::clicked, this, &FileOpenDialog::openStpFile); // 复用槽函数
    connect(openAedtButton, &QPushButton::clicked, this, &FileOpenDialog::openAedtFile);
}

void FileOpenDialog::openStpFile()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open STP/STEP File"), "", tr("STP Files (*.stp);;STEP Files (*.step);"));
    if (!fileName.isEmpty()) {
        qDebug() << "Selected STP/STEP file:" << fileName;

        // 使用 Open CASCADE 读取 .stp 文件
        // STEPControl_Reader reader;
        // if (reader.ReadFile(fileName.toStdString().c_str()) == IFSelect_RetDone) {
        //     reader.TransferRoots();
        //     TopoDS_Shape shape = reader.OneShape();

        //     // 遍历形状中的顶点并打印其坐标
        //     for (TopExp_Explorer explorer(shape, TopAbs_VERTEX); explorer.More(); explorer.Next()) {
        //         TopoDS_Vertex vertex = TopoDS::Vertex(explorer.Current());
        //         gp_Pnt point = BRep_Tool::Pnt(vertex);
        //         qDebug() << "Vertex at:" << point.X() << point.Y() << point.Z();
        //     }
    }
}

void FileOpenDialog::openAedtFile()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open AEDT File"), "", tr("AEDT Files (*.aedt);"));
    if (!fileName.isEmpty()) {
        qDebug() << "Selected AEDT file:" << fileName;

        // 使用 QProcess 调用 Python 脚本
        // QProcess process;
        // QString scriptPath = "path/to/open_aedt.py"; // 替换为你的脚本路径
        // process.start("python", QStringList() << scriptPath << fileName);
        // process.waitForFinished();
        // QString output = process.readAllStandardOutput();
        // qDebug() << "Python script output:" << output;
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值