函数名
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();
}