• Qt通用方法及类库12


    函数名

        //初始化表格
        static void initTableView(QTableView *tableView, int rowHeight = 25, bool headVisible = false, bool edit = false);
    
        //弹出消息框
        static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
        //弹出错误框
        static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false);
        //弹出询问框
        static int showMessageBoxQuestion(const QString &info);
    
        //弹出+隐藏右下角信息框
        static void showTipBox(const QString &title, const QString &tip, bool fullScreen = false,
                               bool center = true, int closeSec = 0);
        static void hideTipBox();
    
        //弹出输入框
        static QString showInputBox(const QString &title, int type = 0, int closeSec = 0,
                                    const QString &placeholderText = QString(), bool pwd = false,
                                    const QString &defaultValue = QString());
        //弹出日期选择框
        static void showDateSelect(QString &dateStart, QString &dateEnd, const QString &format = "yyyy-MM-dd");
    
    

    函数体

    void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit)
    {
        //奇数偶数行颜色交替
        tableView->setAlternatingRowColors(false);
        //垂直表头是否可见
        tableView->verticalHeader()->setVisible(headVisible);
        //选中一行表头是否加粗
        tableView->horizontalHeader()->setHighlightSections(false);
        //最后一行拉伸填充
        tableView->horizontalHeader()->setStretchLastSection(true);
        //行标题最小宽度尺寸
        tableView->horizontalHeader()->setMinimumSectionSize(0);
        //行标题最大高度
        tableView->horizontalHeader()->setMaximumHeight(rowHeight);
        //默认行高
        tableView->verticalHeader()->setDefaultSectionSize(rowHeight);
        //选中时一行整体选中
        tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
        //只允许选择单个
        tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    
        //表头不可单击
    #if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
        tableView->horizontalHeader()->setSectionsClickable(false);
    #else
        tableView->horizontalHeader()->setClickable(false);
    #endif
    
        //鼠标按下即进入编辑模式
        if (edit) {
            tableView->setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::DoubleClicked);
        } else {
            tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
        }
    }
    
    void QUIHelper::showMessageBoxInfo(const QString &info, int closeSec, bool exec)
    {
    #ifdef Q_OS_ANDROID
        QAndroid::Instance()->makeToast(info);
    #else
        if (exec) {
            QUIMessageBox msg;
            msg.setMessage(info, 0, closeSec);
            msg.exec();
        } else {
            QUIMessageBox::Instance()->setMessage(info, 0, closeSec);
            QUIMessageBox::Instance()->show();
        }
    #endif
    }
    
    void QUIHelper::showMessageBoxError(const QString &info, int closeSec, bool exec)
    {
    #ifdef Q_OS_ANDROID
        QAndroid::Instance()->makeToast(info);
    #else
        if (exec) {
            QUIMessageBox msg;
            msg.setMessage(info, 2, closeSec);
            msg.exec();
        } else {
            QUIMessageBox::Instance()->setMessage(info, 2, closeSec);
            QUIMessageBox::Instance()->show();
        }
    #endif
    }
    
    int QUIHelper::showMessageBoxQuestion(const QString &info)
    {
        QUIMessageBox msg;
        msg.setMessage(info, 1);
        return msg.exec();
    }
    
    void QUIHelper::showTipBox(const QString &title, const QString &tip, bool fullScreen, bool center, int closeSec)
    {
        QUITipBox::Instance()->setTip(title, tip, fullScreen, center, closeSec);
        QUITipBox::Instance()->show();
    }
    
    void QUIHelper::hideTipBox()
    {
        QUITipBox::Instance()->hide();
    }
    
    QString QUIHelper::showInputBox(const QString &title, int type, int closeSec,
                                    const QString &placeholderText, bool pwd,
                                    const QString &defaultValue)
    {
        QUIInputBox input;
        input.setParameter(title, type, closeSec, placeholderText, pwd, defaultValue);
        input.exec();
        return input.getValue();
    }
    
    void QUIHelper::showDateSelect(QString &dateStart, QString &dateEnd, const QString &format)
    {
        QUIDateSelect select;
        select.setFormat(format);
        select.exec();
        dateStart = select.getStartDateTime();
        dateEnd = select.getEndDateTime();
    }
    
  • 相关阅读:
    (4.12)全面解析-SQL事务+隔离级别+阻塞+死锁
    【生产问题】--8KW的数据表导致业务卡顿
    (4.6)数据页深入探索--内部探索聚集索引
    (4.11)DBCC 常用命令
    数据库设计与性能优化
    有些事女人忍受不了
    android系列控件
    java常量
    context startactivity
    AssetManager
  • 原文地址:https://www.cnblogs.com/feiyangqingyun/p/12732245.html
Copyright © 2020-2023  润新知