函數名
<code> //初始化表格
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");/<code>
函數體
<code>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();
}/<code>
閱讀更多 Qt自定義控件 的文章