此控件将分两篇实现,给出一个具体的实现思路和大部分代码,作者博客中的代码仅提供学习使用,商业用途请与作者联系。
话不多说,先看效果图
通过图可以看到导航面板分两种样式,1是侧边垂直条,和全尺寸窗格。
导航列表视图支持以下功能:
a、自由选择和切换导航模式,垂直导航条或窗格导航面板。
b、垂直导航条支持左侧和右侧停靠
c、自由控制鼠标悬停时是否显示导航提示
d、自定义导航栏各种颜色和大小
e、自定义导航栏按钮文字
f、发送导航按钮选中时索引数据
g、通过索引设置导航按钮选中
h、自定义控制导航条或面板的显示
注意:带导航的基础列表并不提供具体的导航功能,仅提供导航索引的信号发送和选中导航的槽函数实现,以及各种属性设置,因此要实现具体的导航功能需要继承此列表视图 然后在使用中自行实现,在后续的文章中我们会陆续给出参考代码和使用方法。
此控件的技术关键非常简单,话不多说,我们进入正题
1、侧边垂直导航条:是一个QFrame上放了一个垂直布局,并添加了29个QPushButton,早期也考虑过纯绘制但后来因工作量颇大所以放弃,也考虑过QToolButton,后来由于样式设置受限较大而放弃。在垂直导航条上 鼠标悬停时会弹出一个提醒箭头,这是一个独立的QFrame,上面的箭头和文字是绘制出来的。
问题:为什么使用QFrame:也曾尝试过QWidget,但QWidge在作为子控件时会出现一些不可预料的情况,比如设置的背景qss会有的地方有效 有的地方无效,而且可能存在被遮挡的概率,而QFrame则没有这个问题。说白了 导航条就是添加到QListView上的一个QFrame。而这个frame支持通过设置QSS来定义自定义样式。
2、窗格导航面板。同理还是使用QFrame,并且通过GridLayout布局将30个QPushButton添加进去,然后在需要的时候显示在QListView上,并且和QListView的size保持同步,导航面板在使用时一定要设置不透明的背景色,否则会显示出列表内容,看起来非常怪异。
下面是重要代码部分,首先是垂直导航按钮悬停时的TipFrame的实现。通过一个三角形和一个圆形绘制出箭头样式。
头文件代码如下:
class Lncf_QTooltipFrame : public QFrame
{
Q_OBJECT
Q_PROPERTY(uint uTextFontSize READ GetTipsFontSize WRITE SetTipsFontSize) //字体大小
Q_PROPERTY(QFont fTextFontObjs READ GetTextFontObjs WRITE SetTextFontObjs) //文字字体对象
Q_PROPERTY(uint uDockAlignVal READ GetDockAlignVal WRITE SetDockAlignVal) //停靠位置索引
Q_PROPERTY(double dRadiusValues READ GetRadiusValues WRITE SetRadiusValues) //圆角比例,0-0.5。0
Q_PROPERTY(QColor cBkgColorsVal READ GetBkgColorsVal WRITE SetBkgColorsVal) //背景色
Q_PROPERTY(QColor cArrowsColors READ GetArrowsColors WRITE SetArrowsColors) //箭头背景色
Q_PROPERTY(QColor cTextColorVal READ GetTextColorVal WRITE SetTextColorVal) //文字颜色
public:
Lncf_QTooltipFrame(QWidget *parent = nullptr);
~Lncf_QTooltipFrame();
public:
/// 获取控件信息
/// \brief GetSocialCtlInfo
/// \return
///
LNCFQT_SOCIALCTL_INF GetSocialCtlInfo();
/// 获取字体大小
/// \brief GetTipsFontSize
/// \return
///
uint GetTipsFontSize() const;
/// 获取文字字体对象
/// \brief GetTextFontObjs
/// \return
///
QFont GetTextFontObjs() const;
/// 获取停靠位置索引
/// \brief GetDockAlignVal
/// \return
///
uint GetDockAlignVal() const;
/// 获取圆角比例,0-0.5。0
/// \brief GetRadiusValues
/// \return
///
double GetRadiusValues() const;
/// 获取背景色
/// \brief GetBkgColorsVal
/// \return
///
QColor GetBkgColorsVal() const;
/// 获取箭头背景色
/// \brief GetArrowsColors
/// \return
///
QColor GetArrowsColors() const;
/// 获取文字颜色
/// \brief GetTextColorVal
/// \return
///
QColor GetTextColorVal() const;
public slots:
/// 设置提醒文字
/// \brief SetToolTipsText
/// \param sText
///
void SetToolTipsText(std::u16string sText);
/// 设置字体大小
/// \brief SetTipsFontSize
/// \param uSize
///
void SetTipsFontSize(const uint uSize);
/// 设置字体对象
/// \brief SetTextFontObjs
/// \param font
///
void SetTextFontObjs(const QFont font);
/// 更新停靠位置,0左,1右,2上,3下
/// \brief SetDockAlignVal
/// \param uValue
///
void SetDockAlignVal(const uint uValue);
/// 设置圆角比例,0-0.5。0
/// \brief SetRadiusValues
/// \param dValue
///
void SetRadiusValues(const double dValue);
/// 设置背景色
/// \brief SetBkgColorsVal
/// \param cValue
///
void SetBkgColorsVal(const QColor cValue);
/// 设置箭头背景色
/// \brief SetArrowsColors
/// \param cValue
///
void SetArrowsColors(const QColor cValue);
/// 设置文字颜色
/// \brief SetTextColorVal
/// \param cValue
///
void SetTextColorVal(const QColor cValue);
private:
uint uTextFontSize = 9; //字体大小
QFont fTextFontObjs; //文字字体对象
uint uDockAlignVal = 1; //停靠位置索引
double dRadiusValues = 0.5; //圆角比例,0-0.5。0
QColor cBkgColorsVal = QColor(42,166,138); //背景色
QColor cArrowsColors = QColor(37,148,123); //箭头背景色
QColor cTextColorVal = QColor(240,240,240);//文字颜色
QString sToolTipsText = ""; //显示文字
QGraphicsDropShadowEffect *pToolTipShadow = nullptr;
protected:
///重写绘制
void paintEvent(QPaintEvent *event);
QSize sizeHint() const;
QSize minimumSizeHint() const;
void leaveEvent(QEvent *event);
CPP实现文件代码如下:
Lncf_QTooltipFrame::Lncf_QTooltipFrame(QWidget *parent) : QFrame(parent)
{
setAttribute(Qt::WA_TranslucentBackground, true);
setWindowFlags(Qt::SplashScreen | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
fTextFontObjs = this->font();
this->setFixedWidth(0);
this->hide();
}
Lncf_QTooltipFrame::~Lncf_QTooltipFrame()
{
}
/// 获取控件信息
/// \brief GetSocialCtlInfo
/// \return
///
LNCFQT_SOCIALCTL_INF Lncf_QTooltipFrame::GetSocialCtlInfo()
{
return {typeid (this).name(),tr("Social Tooltip Frame Control")};
}
/// 获取字体大小
/// \brief GetTipsFontSize
/// \return
///
uint Lncf_QTooltipFrame::GetTipsFontSize() const
{
return this->uTextFontSize;
}
/// 获取文字字体对象
/// \brief GetTextFontObjs
/// \return
///
QFont Lncf_QTooltipFrame::GetTextFontObjs() const
{
return this->fTextFontObjs;
}
/// 获取停靠位置索引
/// \brief GetDockAlignVal
/// \return
///
uint Lncf_QTooltipFrame::GetDockAlignVal() const
{
return this->uDockAlignVal;
}
/// 获取圆角比例,0-0.5。0
/// \brief GetRadiusValues
/// \return
///
double Lncf_QTooltipFrame::GetRadiusValues() const
{
return this->dRadiusValues;
}
/// 获取背景色
/// \brief GetBkgColorsVal
/// \return
///
QColor Lncf_QTooltipFrame::GetBkgColorsVal() const
{
return this->cBkgColorsVal;
}
/// 获取箭头背景色
/// \brief GetArrowsColors
/// \return
///
QColor Lncf_QTooltipFrame::GetArrowsColors() const
{
return this->cArrowsColors;
}
/// 获取文字颜色
/// \brief GetTextColorVal
/// \return
///
QColor Lncf_QTooltipFrame::GetTextColorVal() const
{
return this->cTextColorVal;
}
/// 设置提醒文字
/// \brief SetToolTipsText
/// \param sText
///
void Lncf_QTooltipFrame::SetToolTipsText(std::u16string sText)
{
QPainter painter(this);
fTextFontObjs.setPointSize(uTextFontSize);
painter.setFont(fTextFontObjs);
QFontMetrics fm = painter.fontMetrics();
if(sText.length()>128)
sText=sText.substr(0,128);
sToolTipsText = QString::fromStdU16String(sText);
int txtWidth = fm.horizontalAdvance(sToolTipsText);
if(txtWidth<this->height())
txtWidth=this->height();
this->setFixedWidth(txtWidth+12);
this->update();
this->show();
}
/// 设置字体大小
/// \brief SetTipsFontSize
/// \param uSize
///
void Lncf_QTooltipFrame::SetTipsFontSize(uint uSize)
{
uTextFontSize = uSize;
this->update();
}
/// 设置字体对象
/// \brief SetTextFontObjs
/// \param font
///
void Lncf_QTooltipFrame::SetTextFontObjs(const QFont font)
{
if(this->fTextFontObjs!=font)
{
this->fTextFontObjs=font;
this->update();
}
}
/// 更新停靠位置,0左,1右,2上,3下
/// \brief UpdateDockAlign
/// \param uAlign
///
void Lncf_QTooltipFrame::SetDockAlignVal(const uint uAlign)
{
if(uAlign>=0&&uAlign<4)
{
uDockAlignVal = uAlign;
this->update();
}
}
/// 设置圆角比例,0-0.5。0
/// \brief SetRadiusValues
/// \param dValue
///
void Lncf_QTooltipFrame::SetRadiusValues(const double dValue)
{
if(this->dRadiusValues!=dValue&&dValue>-0.01&&dValue<0.501)
{
this->dRadiusValues=dValue;
this->update();
}
}
/// 设置背景色
/// \brief SetBkgColorsVal
/// \param cValue
///
void Lncf_QTooltipFrame::SetBkgColorsVal(const QColor cValue)
{
if(this->cBkgColorsVal!=cValue)
{
this->cBkgColorsVal=cValue;
this->update();
}
}
/// 设置箭头背景色
/// \brief SetArrowsColors
/// \param cValue
///
void Lncf_QTooltipFrame::SetArrowsColors(const QColor cValue)
{
if(this->cArrowsColors!=cValue)
{
this->cArrowsColors=cValue;
this->update();
}
}
/// 设置文字颜色
/// \brief SetTextColorVal
/// \param cValue
///
void Lncf_QTooltipFrame::SetTextColorVal(const QColor cValue)
{
if(this->cTextColorVal!=cValue)
{
this->cTextColorVal=cValue;
this->update();
}
}
///重写绘制
void Lncf_QTooltipFrame::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
painter.save();
painter.setPen(Qt::NoPen);
painter.setBrush(cBkgColorsVal);
QRectF rcRect;
//绘制在右侧中间,根据设定的倒三角的边长设定三个点位置
int width = 24;
int height = this->height();
int midHeight = height / 2;
QPolygon pts;
int ptsLen=10;
switch (uDockAlignVal) {
case 0: //左侧
rcRect = QRectF(this->rect().left()+6,this->rect().top()+6,this->rect().width()-24,this->rect().height()-12);
pts.setPoints(3, this->width()-6, midHeight, this->width()-24, midHeight - ptsLen, this->width()-24, midHeight + ptsLen);
break;
case 1: //右侧边数
rcRect = QRectF(this->rect().left()+12,this->rect().top()+6,this->rect().width()-24,this->rect().height()-12);
pts.setPoints(3, 2, midHeight, width, midHeight - ptsLen, width, midHeight + ptsLen);
break;
case 2: //顶部
rcRect = QRectF(this->rect().left()+6,this->rect().top()+6,this->rect().width()-12,this->rect().height()-18);
pts.setPoints(3, this->width()/2, this->rect().height()-4, this->width()/2 - ptsLen, this->rect().height()-18, this->width()/2 + ptsLen, this->rect().height()-18);
break;
case 3: //底部
rcRect = QRectF(this->rect().left()+6,this->rect().top()+12,this->rect().width()-12,this->rect().height()-18);
pts.setPoints(3, this->width()/2, 4, this->width()/2 - ptsLen, 18, this->width()/2 + ptsLen, 18);
break;
}
painter.drawPolygon(pts);
painter.setBrush(cArrowsColors);
painter.drawRoundedRect(rcRect,rcRect.height()*dRadiusValues,rcRect.height()*dRadiusValues);
painter.setPen(QColor(cTextColorVal));
QFont fontObj = this->font();
fontObj.setPointSize(uTextFontSize);
painter.setFont(fontObj);
painter.drawText(rcRect,Qt::TextWordWrap|Qt::AlignCenter,sToolTipsText);
painter.restore();
return QFrame::paintEvent(event);
}
QSize Lncf_QTooltipFrame::sizeHint() const
{
return QSize(54,42);
}
QSize Lncf_QTooltipFrame::minimumSizeHint() const
{
return QSize(48,24);
}
void Lncf_QTooltipFrame::leaveEvent(QEvent *event)
{
this->hide();
return QFrame::leaveEvent(event);
}
我们在垂直条中要使用上面的ToolTipFrame,因此首先实现此Frame。接下来我们需要在垂直导航条中来展示此提示信息。
垂直导航条头文件代码如下:
class Lncf_QTooltipFrame;
class Lncf_NavIndexPanel : public QFrame
{
Q_OBJECT
Q_PROPERTY(uint uTextFontSize READ GetTipsFontSize WRITE SetTipsFontSize) //提示字体大小
Q_PROPERTY(QFont fTextFontObjs READ GetTipsFontObjs WRITE SetTipsFontObjs) //提示文字字体对象
Q_PROPERTY(uint uDockAlignVal READ GetDockAlignment WRITE SetDockAlignment)//停靠位置索引
Q_PROPERTY(double dRadiusValues READ GetTipRadiusVal WRITE SetTipRadiusVal) //提示圆角比例,0-0.5。0
Q_PROPERTY(QColor cBkgColorsVal READ GetTipsBkgColor WRITE SetTipsBkgColor) //提示背景色
Q_PROPERTY(QColor cArrowsColors READ GetTipArrowsBkg WRITE SetTipArrowsBkg) //提示箭头背景色
Q_PROPERTY(QColor cTextColorVal READ GetTipsColorVal WRITE SetTipsColorVal) //提示文字颜色
Q_PROPERTY(bool bShowToolTips READ GetIsShowTooltip WRITE SetIsShowTooltip)//是否显示提醒
public:
Lncf_NavIndexPanel(QWidget *parent = nullptr,uint uAlignment=0);
~Lncf_NavIndexPanel();
protected:
/// 初始化控件虚函数
/// \brief InitFriendsList
///
void InitSocialCtrls();
/// 重写系统绘制
/// \brief paintEvent
/// \param event
///
void paintEvent(QPaintEvent *event);
/// 重写系统鼠标移动事件
/// \brief mouseMoveEvent
/// \param event
///
void mouseMoveEvent(QMouseEvent *event);
private:
QPushButton *vNavIndexsBtns[29]; //29个按钮列表
QVBoxLayout *lNaviBtnLayout; //索引按钮容器
QList<std::u16string> sNaviTextsList; //索引按钮文本
bool bHasInitialize = false; //是否初始化
bool bIsShowTooltip = true; //是否显示提醒
uint uDockAlignment = 0; //停靠位置,0左,1右
Lncf_QTooltipFrame *pToolTipsFrame = nullptr;
QGraphicsDropShadowEffect *pToolTipShadow = nullptr;
public:
/// 获取停靠位置索引,0靠左,1靠右
/// \brief GetDockAlignment
/// \return
///
uint GetDockAlignment() const;
/// 获取提醒字体大小
/// \brief GetTipsFontSize
/// \return
///
uint GetTipsFontSize() const;
/// 获取提醒文字字体对象
/// \brief GetTipsFontObjs
/// \return
///
QFont GetTipsFontObjs() const;
/// 获取提醒窗口圆角比例,0-0.5。0
/// \brief GetTipRadiusVal
/// \return
///
double GetTipRadiusVal() const;
/// 获取提醒窗口背景色
/// \brief GetTipsBkgColor
/// \return
///
QColor GetTipsBkgColor() const;
/// 获取提醒窗口箭头背景色
/// \brief GetTipArrowsBkg
/// \return
///
QColor GetTipArrowsBkg() const;
/// 获取提醒窗口文字颜色
/// \brief GetTipsColorVal
/// \return
///
QColor GetTipsColorVal() const;
/// 获取是否显示导航提醒
/// \brief GetIsShowTooltip
/// \return
///
bool GetIsShowTooltip() const;
public slots:
/// 按钮选中槽函数
/// \brief OnNavBtnActived
/// \param button
/// \param checked
///
void OnNavBtnActived(const uint uIndex);
/// 按钮单击事件
/// \brief OnNavBtnClicked
/// \param button
///
void OnNavBtnClicked(QAbstractButton *button);
/// 设置导航字符索引,不能小于28个,超过28个将不会被显示
/// \brief SetNaviTextsList
/// \param sList
///
void SetNaviTextsList(QList<std::u16string> sList);
/// 设置选中按钮
/// \brief SetSelectNavBtn
/// \param uIndex :选中的按钮索引0表示所有#按钮,1-26表示字母A到Z,27=数字按钮
///
void SetSelectNavBtn(uint uIndex);
/// 隐藏提醒
/// \brief HideTooltipFrame
///
void HideTooltipFrame();
/// 设置停靠位置
/// \brief SetDockAlignment
/// \param uAlignment 停靠位置,0左,1右
///
void SetDockAlignment(uint uAlignment);
/// 设置提醒字体大小
/// \brief SetTipsFontSize
/// \param uSize
///
void SetTipsFontSize(const uint uSize);
/// 设置提醒文字字体对象
/// \brief SetTipsFontObjs
/// \param fObj
///
void SetTipsFontObjs(const QFont fObj);
/// 设置提醒窗口圆角比例,0-0.5。0
/// \brief SetTipRadiusVal
/// \param dValue
///
void SetTipRadiusVal(const double dValue);
/// 设置提醒窗口背景色
/// \brief SetTipsBkgColor
/// \param cValue
///
void SetTipsBkgColor(const QColor cValue);
/// 设置提醒窗口箭头背景色
/// \brief SetTipArrowsBkg
/// \param cValue
///
void SetTipArrowsBkg(const QColor cValue);
/// 设置提醒窗口文字颜色
/// \brief SetTipsColorVal
/// \param cValue
///
void SetTipsColorVal(const QColor cValue);
/// 设置是否显示导航提醒
/// \brief SetIsShowTooltip
/// \param bValue
///
void SetIsShowTooltip(const bool &bValue);
private:
/// 显示提示按钮
/// \brief ShowToolTipsWnd
/// \param uIndex
///
void ShowToolTipsWnd(uint uIndex);
signals:
/// 按钮选中事件
/// \brief NavBtnCheckEvts
/// \param uIndex :选中的按钮索引0表示所有#按钮,1-26表示字母A到Z,27=数字按钮
///
void NavBtnCheckEvts(const uint uIndex);
代码中注释很明确,因此文章中不再赘述,通过看代码就能明白意思
接下来实现垂直导航条,代码如下
Lncf_NavIndexPanel::Lncf_NavIndexPanel(QWidget *parent,uint uAlignment) : QFrame(parent)
{
uDockAlignment = uAlignment;
this->InitSocialCtrls();
}
Lncf_NavIndexPanel::~Lncf_NavIndexPanel()
{
}
/// 初始化控件虚函数
/// \brief InitFriendsList
///
void Lncf_NavIndexPanel::InitSocialCtrls()
{
pToolTipShadow = new QGraphicsDropShadowEffect(this);
pToolTipShadow->setOffset(0, 0);
pToolTipShadow->setColor(QColor(0, 0, 0, 160));
pToolTipShadow->setBlurRadius(6);
sNaviTextsList = {u"#",u"A",u"B",u"C",u"D",u"E",u"F",u"G",u"H",u"I",u"J",u"K",u"L",u"M",u"N",u"O",u"P",u"Q",u"R",u"S",u"T",u"U",u"V",u"W",u"X",u"Y",u"Z",u"❉",u"☼"};
lNaviBtnLayout = new QVBoxLayout();
lNaviBtnLayout->setContentsMargins(1,8,1,8);
lNaviBtnLayout->setSpacing(2);
this->setLayout(lNaviBtnLayout);
QButtonGroup *buttonsGroup = new QButtonGroup(this);
buttonsGroup->setExclusive(true);
if(sNaviTextsList.count()==29){
for(int i=0;i<29;i++){
vNavIndexsBtns[i] =new QPushButton(this);
vNavIndexsBtns[i]->setText(QString::fromStdU16String(sNaviTextsList[i]));
vNavIndexsBtns[i]->setCheckable(true);
vNavIndexsBtns[i]->setMouseTracking(true);
lNaviBtnLayout->addWidget(vNavIndexsBtns[i]);
buttonsGroup->addButton(vNavIndexsBtns[i]);
}
}
connect(buttonsGroup, static_cast<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked),
this, &Lncf_NavIndexPanel::OnNavBtnClicked);
bHasInitialize = true;
this->adjustSize();
this->setMouseTracking(true);
pToolTipsFrame= new Lncf_QTooltipFrame();
pToolTipsFrame->SetTipsFontSize(11);
}
void Lncf_NavIndexPanel::paintEvent(QPaintEvent *event) //实现
{
//非常重要,下面的代码将使得Qss设置对此类可用
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
QFrame::paintEvent(event);
}
/// 重写系统鼠标移动事件
/// \brief mouseMoveEvent
/// \param event
///
void Lncf_NavIndexPanel::mouseMoveEvent(QMouseEvent *event)
{
if(event&&bHasInitialize&&bIsShowTooltip)
{
for(int i=0;i<29;i++){
if(vNavIndexsBtns[i]->underMouse()){
ShowToolTipsWnd(i);
break;
}
}
}
return QFrame::mouseMoveEvent(event);
}
/// 获取控件信息
/// \brief GetSocialCtlInfo
/// \return
///
LNCFQT_SOCIALCTL_INF Lncf_NavIndexPanel::GetSocialCtlInfo()
{
return {typeid (this).name(),tr("Social Navigate Index Frame Control")};
}
/// 获取导航字符索引
/// \brief GetNaviTextsList
/// \return
///
QList<std::u16string> Lncf_NavIndexPanel::GetNaviTextsList() const
{
return this->sNaviTextsList;
}
/// 获取停靠位置索引,0靠左,1靠右
/// \brief GetDockAlignment
/// \return
///
uint Lncf_NavIndexPanel::GetDockAlignment() const
{
return this->uDockAlignment;
}
/// 获取提醒字体大小
/// \brief GetTipsFontSize
/// \return
///
uint Lncf_NavIndexPanel::GetTipsFontSize() const
{
return pToolTipsFrame?pToolTipsFrame->GetTipsFontSize():0;
}
/// 获取提醒文字字体对象
/// \brief GetTipsFontObjs
/// \return
///
QFont Lncf_NavIndexPanel::GetTipsFontObjs() const
{
return pToolTipsFrame?pToolTipsFrame->GetTextFontObjs():QFont();
}
/// 获取提醒窗口圆角比例,0-0.5。0
/// \brief GetTipRadiusVal
/// \return
///
double Lncf_NavIndexPanel::GetTipRadiusVal() const
{
return pToolTipsFrame?pToolTipsFrame->GetRadiusValues():0;
}
/// 获取提醒窗口背景色
/// \brief GetTipsBkgColor
/// \return
///
QColor Lncf_NavIndexPanel::GetTipsBkgColor() const
{
return pToolTipsFrame?pToolTipsFrame->GetBkgColorsVal():QColor();
}
/// 获取提醒窗口箭头背景色
/// \brief GetTipArrowsBkg
/// \return
///
QColor Lncf_NavIndexPanel::GetTipArrowsBkg() const
{
return pToolTipsFrame?pToolTipsFrame->GetArrowsColors():QColor();
}
/// 获取提醒窗口文字颜色
/// \brief GetTipsColorVal
/// \return
///
QColor Lncf_NavIndexPanel::GetTipsColorVal() const
{
return pToolTipsFrame?pToolTipsFrame->GetTextColorVal():QColor();
}
/// 获取是否显示导航提醒
/// \brief GetIsShowTooltip
/// \return
///
bool Lncf_NavIndexPanel::GetIsShowTooltip() const
{
return this->bIsShowTooltip;
}
/// 按钮选中槽函数
/// \brief OnNavBtnActived
/// \param button
/// \param checked
///
void Lncf_NavIndexPanel::OnNavBtnActived(const uint uIndex)
{
//实现按钮激活函数
}
/// 按钮单击事件
/// \brief OnNavBtnClicked
/// \param button
///
void Lncf_NavIndexPanel::OnNavBtnClicked(QAbstractButton *button)
{
//实现按钮选中函数
}
/// 设置导航字符索引
/// \brief SetNaviTextsList
/// \param sList
///
void Lncf_NavIndexPanel::SetNaviTextsList(QList<std::u16string> sList)
{
if(sList.count()<29)
return;
for(int i=0;i<29;i++)
{
if(sList[i].length()>1)
sList[i]=sList[i].substr(0,1);
}
this->sNaviTextsList = sList;
}
/// 设置选中按钮
/// \brief SetSelectNavBtn
/// \param uIndex :选中的按钮索引0表示所有#按钮,1-26表示字母A到Z,27=数字按钮
///
void Lncf_NavIndexPanel::SetSelectNavBtn(uint uIndex)
{
if(uIndex>=0&&uIndex<29)
{
vNavIndexsBtns[uIndex]->setChecked(true);
}
}
/// 隐藏提醒
/// \brief HideTooltipFrame
///
void Lncf_NavIndexPanel::HideTooltipFrame()
{
if(pToolTipsFrame) pToolTipsFrame->hide();
}
/// 设置停靠位置
/// \brief SetDockAlignment
/// \param uAlignment 停靠位置,0左,1右
///
void Lncf_NavIndexPanel::SetDockAlignment(uint uAlignment)
{
if(uAlignment>=0&&uAlignment<2){
uDockAlignment=uAlignment;
if(pToolTipsFrame)
{
//0左,1右,2上,3下
pToolTipsFrame->SetDockAlignVal(uAlignment==0?1:0);
}
}
}
/// 设置提醒字体大小
/// \brief SetTipsFontSize
/// \param uSize
///
void Lncf_NavIndexPanel::SetTipsFontSize(const uint uSize)
{
if(pToolTipsFrame)pToolTipsFrame->SetTipsFontSize(uSize);
}
/// 设置提醒文字字体对象
/// \brief SetTipsFontObjs
/// \param fObj
///
void Lncf_NavIndexPanel::SetTipsFontObjs(const QFont fObj)
{
if(pToolTipsFrame)pToolTipsFrame->SetTextFontObjs(fObj);
}
/// 设置提醒窗口圆角比例,0-0.5。0
/// \brief SetTipRadiusVal
/// \param dValue
///
void Lncf_NavIndexPanel::SetTipRadiusVal(const double dValue)
{
if(pToolTipsFrame)pToolTipsFrame->SetRadiusValues(dValue);
}
/// 设置提醒窗口背景色
/// \brief SetTipsBkgColor
/// \param cValue
///
void Lncf_NavIndexPanel::SetTipsBkgColor(const QColor cValue)
{
if(pToolTipsFrame)pToolTipsFrame->SetBkgColorsVal(cValue);
}
/// 设置提醒窗口箭头背景色
/// \brief SetTipArrowsBkg
/// \param cValue
///
void Lncf_NavIndexPanel::SetTipArrowsBkg(const QColor cValue)
{
if(pToolTipsFrame)pToolTipsFrame->SetArrowsColors(cValue);
}
/// 设置提醒窗口文字颜色
/// \brief SetTipsColorVal
/// \param cValue
///
void Lncf_NavIndexPanel::SetTipsColorVal(const QColor cValue)
{
if(pToolTipsFrame)pToolTipsFrame->SetTextColorVal(cValue);
}
/// 设置是否显示导航提醒
/// \brief SetIsShowTooltip
/// \param bValue
///
void Lncf_NavIndexPanel::SetIsShowTooltip(const bool &bValue)
{
this->bIsShowTooltip = bValue;
}
/// 显示提示按钮
/// \brief ShowToolTipsWnd
/// \param uIndex
///
void Lncf_NavIndexPanel::ShowToolTipsWnd(uint uIndex)
{
/*在此处实现当鼠标移动上来之后显示的提示,可以用QtoolTip或者其他自定义的提示组件*/
}
由于作者时间有限,因此就先到这里,下一篇中我们将给出窗格导航和ListView的封装代码和说明。
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/wastelandboy/article/details/122891759
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/wastelandboy/article/details/122891759