• RxCpp(四)Qt/GUI编程


    Qt简介

    Qt(发音可爱)生态系统是一个全面的基于c++的框架,用于编写跨平台和多平台GUI应用程序。如果使用库的可移植核心编写程序,则可以利用框架支持的一次编写和到处编译范例。在某些情况下,人们使用特定于平台的特性,比如支持Activex编程模型来编写基于windows的应用程序。
    在windows中编写应用程序时,我们会遇到qt优于mfc的情况。这样做的一个合理原因可能是易于编程,因为qt为其库使用了非常小的c++语言特性子集。当然,框架的最初目标是跨平台开发。Qt的跨平台的单一源代码可移植性、特性的丰富性、源代码的可用性以及更新良好的文档,使其成为一个非常适合程序员的框架。自1995年第一次发行以来,这帮助它在20多年的时间里蓬勃发展。
    Qt提供了一个完整的接口环境,支持开发多平台GUI应用程序、webkit API、媒体、流媒体、文件系统浏览器、OpenGL API等等。


    rxqt简介

    rxqt库是一个写在rxcpp库上的公共域库,它使用qt事件和信号以反应性的方式进行编程变得很容易。为了理解这个库,让我们进入一个示例,这样我们就可以跟踪鼠标事件,并使用库提供的observable来过滤它们。该库的下载以及更多示例见:rxqt:


    #include <QApplication>
    #include <QLabel>
    #include <QWidget>
    #include <QVBoxLayout>
    #include <QMouseEvent>
    #include "rxqt.hpp"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        // Create the application window
        auto widget = std::unique_ptr<QWidget>(new QWidget());
        widget->resize(280, 200);
    
        // Create and set properties of mouse area label
        auto label_mouseArea = new QLabel("Mouse Area");
        label_mouseArea->setMouseTracking(true);
        label_mouseArea->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
        label_mouseArea->setFrameStyle(2);
    
        // Create and set properties of message display label
        auto label_coordinates = new QLabel("X = 0, Y = 0");
        label_coordinates->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
        label_coordinates->setFrameStyle(2);
    
        // Adjusting the size policy of widgets to allow stretching inside the vertical layout
        label_mouseArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        label_coordinates->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    
        auto layout = new QVBoxLayout;
        layout->addWidget(label_mouseArea);
        layout->addWidget(label_coordinates);
        layout->setStretch(0, 4);
        layout->setStretch(1, 1);
        widget->setLayout(layout);
    
        // Display the mouse move message and the mouse coordinates
        rxqt::from_event(label_mouseArea, QEvent::MouseMove)
            .subscribe([&label_coordinates](const QEvent* e) {
            auto me = static_cast<const QMouseEvent*>(e);
            label_coordinates->setText(QString("Mouse Moving : X = %1, Y = %2")
                .arg(me->x())
                .arg(me->y()));
                });
    
        // Display the mouse signle click message and the mouse coordinates
        rxqt::from_event(label_mouseArea, QEvent::MouseButtonPress)
            .subscribe([&label_coordinates](const QEvent* e) {
            auto me = static_cast<const QMouseEvent*>(e);
            label_coordinates->setText(QString("Mouse Single click at X = %1, Y = %2")
                .arg(me->x())
                .arg(me->y()));
                });
    
        // Display the mouse double click message and the mouse coordinates
        rxqt::from_event(label_mouseArea, QEvent::MouseButtonDblClick)
            .subscribe([&label_coordinates](const QEvent* e) {
            auto me = static_cast<const QMouseEvent*>(e);
            label_coordinates->setText(QString("Mouse Double click at X = %1, Y = %2")
                .arg(me->x())
                .arg(me->y()));
                });
    
        widget->show();
        return app.exec();
    } // End of main
  • 相关阅读:
    jstl动态生成下拉列表框
    nested exception is java.lang.NoClassDefFoundError:org/hibernate/engine/SessionFactoryImplementor
    java.lang.NoSuchMethodError: ognl.SimpleNode.isEvalChain(Lognl/OgnlContext;)Z
    java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
    java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()Z
    substring(int beginIndex,int length)的参数
    reverse() 颠倒StringBuffer对象中的字符
    jsp servlet 分页
    & | && ||
    C++ 导入导出
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/16323705.html
Copyright © 2020-2023  润新知