• 设置QPushButton的平面与突出(遍历控件)


    #include "ui_maindialog.h"
    #include "maindialog.h"
    
    #include <QState>
    #include <QEventTransition>
    #include <QStateMachine>
    #include <qDebug>
    
    
    MainDialog::MainDialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::MainDialog)
    {
        ui->setupUi(this);
        setWindowFlags(Qt::WindowStaysOnTopHint);
    
    
        /*遍历界面上所有button*/
        QList<QPushButton *> button = this->findChildren<QPushButton *>();
        qDebug() << button.count();
        for(int i=0; i < button.count(); i++)//通过i的范围确定需要设置哪些button
        {
            setDynamicImage(button.at(i));
        }
    }
    
    
    
    
    void MainDialog::setDynamicImage(QPushButton *button)
    {
    
    
        /*定义两种状态(鼠标进入button/退出button)*/
        QState *inside = new QState;
        inside->assignProperty(button,"flat", "false");//设置button为凸起
        QState *outside = new QState;
        outside->assignProperty(button, "flat", "true");//设置button为平面
    
    
        /*把进入、退出事件与button关联*/
        QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter);
        enterTransition->setTargetState(inside);//鼠标进入button
        outside->addTransition(enterTransition);//把outside状态,连接到enterTransition变化中去
    
    
        QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave);
        leaveTransition->setTargetState(outside);//鼠标退出button
        inside->addTransition(leaveTransition);//把inside状态,连接到leaveTransition变化中去
    
    
        /*定义状态机*/
        QStateMachine *machine = new QStateMachine(this);
    
    
        /*在状态机中添加这两种状态*/
        machine->addState(inside);
        machine->addState(outside);
    
    
        /*设置初始状态*/
        machine->setInitialState(outside);
    
    
        /*启动状态机*/
        machine->start();
    }
    
    
    MainDialog::~MainDialog()
    {
        delete ui;
    }

    http://blog.csdn.net/mingxia_sui/article/details/7760163
  • 相关阅读:
    SOA概念误解实施要点
    Visual Studio 2008 和 .NET Framework 3.5 Service Pack 1 Beta 发布
    【翻译】使用LINQ来简化编程的7个技巧
    我对SOA的认识以及心得
    《SQL Server 2005范例代码查询辞典》出版
    Security Tutorials系列文章以及AJAX系列文章
    代朋友发招聘信息,C++程序员
    二叉树相关算法
    最近项目的一些心得(纯贴代码)
    大型互联网网站架构心得之一:分
  • 原文地址:https://www.cnblogs.com/findumars/p/5553933.html
Copyright © 2020-2023  润新知