ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Qt通用方法及类库12

2021-06-02 11:02:37  阅读:187  来源: 互联网

标签:类库 12 const Qt tableView int bool QString closeSec


函数名

    //初始化表格
    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();
}

标签:类库,12,const,Qt,tableView,int,bool,QString,closeSec
来源: https://blog.51cto.com/u_15246509/2845038

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有