QTmainwindow的菜单栏工具栏实现在textedit显示以及事件处理

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();
    QString getProjectPath();
    QString getCompiler();
    QString getColorPlan();
    bool getIndent();
    bool getAutoComplete();

signals:
    void sendData(QString,QString,QString,bool,bool);
QString Dialog::getProjectPath()
{
    QString s=ui->lineEdit->text();
    return s;
}

QString Dialog::getCompiler()
{
    if(ui->radioButton->isChecked())
        return QString("VC++ 6.0");
    else if(ui->radioButton_2->isChecked())
        return QString("VC++ 2012");
    else
        return QString("g++");
}

QString Dialog::getColorPlan()
{
    QListWidgetItem *it =ui->listWidget->currentItem();
    if(it==NULL)
    return " ";
    else
    return it->text();
}

bool Dialog::getIndent()
{
    if(ui->checkBox->isChecked())
        return true;
    else
        return false;
}

bool Dialog::getAutoComplete()
{
    if(ui->checkBox_2->isChecked())
        return true;
    else
        return false;
}
#include <QDialog>
#include <QAction>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QPoint>
namespace Ui {
class Dialog1;
}

class Dialog1 : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog1(QWidget *parent = 0);
    ~Dialog1();
protected:
    void mouseMoveEvent(QMouseEvent *e);
    void mousePressEvent(QMouseEvent *e);
    void keyPressEvent(QKeyEvent *e);
private:
    Ui::Dialog1 *ui;
  ui(new Ui::Dialog1)
{
    ui->setupUi(this);
    setCursor(Qt::CrossCursor);
}

Dialog1::~Dialog1()
{
    delete ui;
}


void Dialog1::mouseMoveEvent(QMouseEvent *e)
{
     ui->label_2->setText("("+QString::number(e->x())+","+QString::number(e->y())+")");
}
void Dialog1::mousePressEvent(QMouseEvent *e)
{
    ui->label->move(e->x()-50,e->y()-60);
}
void Dialog1::keyPressEvent(QKeyEvent *e)
{

    int x=ui->label->x();
    int y=ui->label->y();
//    if(e->modifiers() & Qt::ControlModifier)
    switch (e->key())
    {
    case Qt::Key_W:
    ui->label->move(x,y-20);
        break;
    case Qt::Key_S:
    ui->label->move(x,y+20);
        break;
    case Qt::Key_D:
    ui->label->move(x+20,y);
        break;
    case Qt::Key_A:
    ui->label->move(x-20,y);
        break;
    }
    QDialog::keyPressEvent(e);

}
void MainWindow::on_actionshow_triggered()
{
    Dialog *sh=new Dialog;
    if(sh->exec()==QDialog::Accepted)
    {
        QString s;
        s="工程目录:"+sh->getProjectPath()+"\n";
        s=s+"编译环境"+sh->getCompiler()+"\n";
        s=s+"高亮显示"+sh->getColorPlan()+"\n";
        if(sh->getIndent())
            s=s+"智能缩进:是\n";
        else
            s=s+"智能缩进:否\n";
        if(sh->getAutoComplete())
            s=s+"代码补全:是\n";
        else
            s=s+"代码补全:否\n";
        ui->textEdit->setText(s);
    }


}

void MainWindow::on_actionmove_triggered()
{
    Dialog1 *ev=new Dialog1;
    ev->show();
//    Dialog1 ev;
//    ev.exec();
}

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星河192

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值