首页 > 其他 > 详细

Qt Gui 第三章~第四章

时间:2020-02-09 18:03:41      阅读:109      评论:0      收藏:0      [点我收藏+]

一、图片资源的调用

  技术分享图片

  如上图是我图片存放的位置跟qrc的命名;

  如下则是qrc对应的编写格式;  

<RCC>
<qresource>
    <file>images/icon.png</file>
                      .
                      .
                      .
    <file>images/gotocell.png</file>
</qresource>
</RCC>

  当qrc放置好之后,则需要在pro文件中添加对应的文件配置:RESOURCES = spreadsheet1.qrc

  当完成这些操作之后则可以自由地调用images中存在,并且qrc中已经描述的文件;

  比如:QIcon(":/images/gotocell.png")

  

二、QAction的使用

  任何QT窗口部件都可以有一个与之相关联的QActions列表。当需要统一操作,而各个控件不一样的时候,可以通过QAction来预操作;具体可以看帮助文档;

  比如可以读取存储在action里面的data;

        QAction* action = qobject_cast<QAction*>(sender());
        if (action)
            loadFile(action->data().toString());

  这里通过sender()可以获取触发槽对应的信号的对象;比如:

   connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));

  在about()函数中调用sender();则会返回对应的aboutAction

 

三、QSettings的使用

    QSettings settings("Software Inc.", "Spreadsheet");

    settings.setValue("geometry", saveGeometry());
    settings.setValue("recentFiles", recentFiles);
    settings.setValue("showGrid", showGridAction->isChecked());
    settings.setValue("autoRecalc", autoRecalcAction->isChecked());

  可以通过该类设置对应的key,value到系统中;当该软件再次打开的时候,可以再次获取到之前软件中保存的一些设置;

    QSettings settings("Software Inc.", "Spreadsheet");
    restoreGeometry(settings.value("geometry").toByteArray());
    recentFiles = settings.value("recentFiles").toStringList();
    updateRecentFileActions();
    bool showGrid = settings.value("showGrid", true).toBool();
    showGridAction->setChecked(showGrid);
    bool autoRecalc = settings.value("autoRecalc", true).toBool();
    autoRecalcAction->setChecked(autoRecalc);

 

 

四、模态跟非模态对话框;

  非模态对话框

    findDialog = new FindDialog(this);
    findDialog->show();
    findDialog->raise();
    findDialog->activateWindow();

  模态对话框

GoToCellDialog dialog(this);
dialog.exec()

  当非模态的对话框要变成模态对话框则需要调用函数 findDialog->setModel();

 

 

 

 

Qt Gui 第三章~第四章

原文:https://www.cnblogs.com/czwlinux/p/12287612.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!