Qt C + + ListView basic class encapsulation with navigation function 1

Posted by netman182 on Sat, 12 Feb 2022 05:23:09 +0100

Under the mountain front bridge, there is a fool. A pupil, living in seclusion in a barren mountain. I have a group of dogs and a cat. Like programming, lack of money to do odd jobs. Mathematical history, French in mind. He can cook and wave.

Statement: I'm not a professional Qt developer. The project needs a localized system scenario. Therefore, the author spent four hours getting started with Qt, which opened the battlefield of Qt.

This control will be implemented in two articles, giving a specific implementation idea and most of the code. The code in the author's blog is only for learning and use. For commercial purposes, please contact the author.

If you don't say much, look at the renderings first

As can be seen from the figure, the navigation panel is divided into two styles: 1 is the side vertical bar and the full-size pane.

The navigation list view supports the following functions:

a. Freely select and switch navigation mode, vertical navigation bar or pane navigation panel.

b. The vertical navigation bar supports left and right docking

c. Freely controls whether navigation prompts are displayed when the mouse hovers

d. Customize the various colors and sizes of the navigation bar

e. Customize navigation bar button text

f. Index data when send navigation button is selected

g. Selected by index setting navigation button

h. Custom controls the display of the navigation bar or panel

Note: the basic list with navigation does not provide specific navigation functions, but only provides the signal transmission of navigation index, the slot function implementation of selected navigation, and various attribute settings. Therefore, to realize the specific navigation functions, we need to inherit this list view and implement it in use. We will give reference codes and usage methods in subsequent articles.

The technical key of this control is very simple. We don't say much. Let's get to the point

1. Side vertical navigation bar: a vertical layout is placed on a QFrame, and 29 qpushbuttons are added. In the early stage, pure drawing was also considered, but later it was abandoned due to heavy workload. QToolButton was also considered, and later it was abandoned due to limited style setting. When hovering over the vertical navigation bar, a reminder arrow will pop up. This is an independent QFrame, and the arrow and text on it are drawn.

Question: why use QFrame: I have also tried QWidget, but when QWidget is used as a child control, there will be some unforeseen situations. For example, the background QSS set will be effective in some places, invalid in some places, and there may be a probability of being obscured. However, QFrame does not have this problem. To put it bluntly, {navigation bar is a QFrame added to QListView. This frame supports defining custom styles by setting QSS.

2. Pane navigation panel. Similarly, use QFrame, add 30 qpushbuttons through the GridLayout layout, and then display them on QListView when necessary, and keep pace with the size of QListView. When using the navigation panel, you must set an opaque background color, otherwise the list content will be displayed, which looks very strange.

The following is an important part of the code. The first is the implementation of TipFrame when the vertical navigation button hovers. Draw the arrow style through a triangle and a circle.

The header file code is as follows:

class Lncf_QTooltipFrame : public QFrame
{
    Q_OBJECT
    Q_PROPERTY(uint   uTextFontSize READ GetTipsFontSize WRITE SetTipsFontSize)  //font size
    Q_PROPERTY(QFont  fTextFontObjs READ GetTextFontObjs WRITE SetTextFontObjs)  //Text font object
    Q_PROPERTY(uint   uDockAlignVal READ GetDockAlignVal WRITE SetDockAlignVal)  //Docking location index
    Q_PROPERTY(double dRadiusValues READ GetRadiusValues WRITE SetRadiusValues)  //Fillet scale, 0-0.5. 0
    Q_PROPERTY(QColor cBkgColorsVal READ GetBkgColorsVal WRITE SetBkgColorsVal)  //Background color
    Q_PROPERTY(QColor cArrowsColors READ GetArrowsColors WRITE SetArrowsColors)  //Arrow background color
    Q_PROPERTY(QColor cTextColorVal READ GetTextColorVal WRITE SetTextColorVal)  //Text color
public:
    Lncf_QTooltipFrame(QWidget *parent = nullptr);
    ~Lncf_QTooltipFrame();

public:
    ///Get control information
    /// \brief GetSocialCtlInfo
    /// \return
    ///
    LNCFQT_SOCIALCTL_INF GetSocialCtlInfo();

    ///Get font size
    /// \brief GetTipsFontSize
    /// \return
    ///
    uint GetTipsFontSize() const;

    ///Get text font object
    /// \brief GetTextFontObjs
    /// \return
    ///
    QFont GetTextFontObjs() const;

    ///Get docking location index
    /// \brief GetDockAlignVal
    /// \return
    ///
    uint GetDockAlignVal() const;

    ///Get the fillet scale, 0-0.5. 0
    /// \brief GetRadiusValues
    /// \return
    ///
    double GetRadiusValues() const;

    ///Get background color
    /// \brief GetBkgColorsVal
    /// \return
    ///
    QColor GetBkgColorsVal() const;

    ///Get arrow background color
    /// \brief GetArrowsColors
    /// \return
    ///
    QColor GetArrowsColors() const;

    ///Get text color
    /// \brief GetTextColorVal
    /// \return
    ///
    QColor GetTextColorVal() const;
public slots:

    ///Set reminder text
    /// \brief SetToolTipsText
    /// \param sText
    ///
    void SetToolTipsText(std::u16string sText);

    ///Set font size
    /// \brief SetTipsFontSize
    /// \param uSize
    ///
    void SetTipsFontSize(const uint uSize);

    ///Set font object
    /// \brief SetTextFontObjs
    /// \param font
    ///
    void SetTextFontObjs(const QFont font);

    ///Update docking position, 0 left, 1 right, 2 up, 3 down
    /// \brief SetDockAlignVal
    /// \param uValue
    ///
    void SetDockAlignVal(const uint uValue);

    ///Set the fillet scale, 0-0.5. 0
    /// \brief SetRadiusValues
    /// \param dValue
    ///
    void SetRadiusValues(const double dValue);

    ///Set background color
    /// \brief SetBkgColorsVal
    /// \param cValue
    ///
    void SetBkgColorsVal(const QColor cValue);

    ///Set arrow background color
    /// \brief SetArrowsColors
    /// \param cValue
    ///
    void SetArrowsColors(const QColor cValue);

    ///Set text color
    /// \brief SetTextColorVal
    /// \param cValue
    ///
    void SetTextColorVal(const QColor cValue);

private:
    uint     uTextFontSize = 9;                  //font size
    QFont    fTextFontObjs;                      //Text font object
    uint     uDockAlignVal = 1;                  //Docking location index
    double   dRadiusValues = 0.5;                //Fillet scale, 0-0.5. 0
    QColor   cBkgColorsVal = QColor(42,166,138); //Background color
    QColor   cArrowsColors = QColor(37,148,123); //Arrow background color
    QColor   cTextColorVal = QColor(240,240,240);//Text color
    QString  sToolTipsText = "";                 //display text
    QGraphicsDropShadowEffect *pToolTipShadow = nullptr;
protected:
    ///Rewrite drawing
    void paintEvent(QPaintEvent *event);

    QSize sizeHint() const;

    QSize minimumSizeHint() const;

    void leaveEvent(QEvent *event);

The code of CPP implementation document is as follows:

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()
{

}

///Get control information
/// \brief GetSocialCtlInfo
/// \return
///
LNCFQT_SOCIALCTL_INF Lncf_QTooltipFrame::GetSocialCtlInfo()
{
    return {typeid (this).name(),tr("Social Tooltip Frame Control")};
}

///Get font size
/// \brief GetTipsFontSize
/// \return
///
uint Lncf_QTooltipFrame::GetTipsFontSize() const
{
    return this->uTextFontSize;
}

///Get text font object
/// \brief GetTextFontObjs
/// \return
///
QFont Lncf_QTooltipFrame::GetTextFontObjs() const
{
    return this->fTextFontObjs;
}

///Get docking location index
/// \brief GetDockAlignVal
/// \return
///
uint Lncf_QTooltipFrame::GetDockAlignVal() const
{
    return this->uDockAlignVal;
}

///Get the fillet scale, 0-0.5. 0
/// \brief GetRadiusValues
/// \return
///
double Lncf_QTooltipFrame::GetRadiusValues() const
{
    return this->dRadiusValues;
}

///Get background color
/// \brief GetBkgColorsVal
/// \return
///
QColor Lncf_QTooltipFrame::GetBkgColorsVal() const
{
    return this->cBkgColorsVal;
}

///Get arrow background color
/// \brief GetArrowsColors
/// \return
///
QColor Lncf_QTooltipFrame::GetArrowsColors() const
{
    return this->cArrowsColors;
}

///Get text color
/// \brief GetTextColorVal
/// \return
///
QColor Lncf_QTooltipFrame::GetTextColorVal() const
{
    return this->cTextColorVal;
}

///Set reminder text
/// \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();
}

///Set font size
/// \brief SetTipsFontSize
/// \param uSize
///
void Lncf_QTooltipFrame::SetTipsFontSize(uint uSize)
{
    uTextFontSize = uSize;
    this->update();
}

///Set font object
/// \brief SetTextFontObjs
/// \param font
///
void Lncf_QTooltipFrame::SetTextFontObjs(const QFont font)
{
    if(this->fTextFontObjs!=font)
    {
        this->fTextFontObjs=font;
        this->update();
    }
}

///Update docking position, 0 left, 1 right, 2 up, 3 down
/// \brief UpdateDockAlign
/// \param uAlign
///
void Lncf_QTooltipFrame::SetDockAlignVal(const uint uAlign)
{
    if(uAlign>=0&&uAlign<4)
    {
        uDockAlignVal = uAlign;
        this->update();
    }
}

///Set the fillet scale, 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();
    }
}

///Set background color
/// \brief SetBkgColorsVal
/// \param cValue
///
void Lncf_QTooltipFrame::SetBkgColorsVal(const QColor cValue)
{
    if(this->cBkgColorsVal!=cValue)
    {
        this->cBkgColorsVal=cValue;
        this->update();
    }
}

///Set arrow background color
/// \brief SetArrowsColors
/// \param cValue
///
void Lncf_QTooltipFrame::SetArrowsColors(const QColor cValue)
{
    if(this->cArrowsColors!=cValue)
    {
        this->cArrowsColors=cValue;
        this->update();
    }
}

///Set text color
/// \brief SetTextColorVal
/// \param cValue
///
void Lncf_QTooltipFrame::SetTextColorVal(const QColor cValue)
{
    if(this->cTextColorVal!=cValue)
    {
        this->cTextColorVal=cValue;
        this->update();
    }
}

///Rewrite drawing
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;

    //Draw it in the middle of the right side, and set three point positions according to the set edge length of the inverted triangle
    int width = 24;
    int height = this->height();
    int midHeight = height / 2;

    QPolygon pts;
    int ptsLen=10;
    switch (uDockAlignVal) {
    case 0:  //left
        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:  //Number of right sides
        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:  //Top
        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:  //bottom
        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);
}

We want to use the above ToolTipFrame in the vertical bar, so we should implement this Frame first. Next, we need to display this prompt in the vertical navigation bar.

The code of vertical navigation header file is as follows:

class Lncf_QTooltipFrame;
class Lncf_NavIndexPanel : public QFrame
{
    Q_OBJECT
    Q_PROPERTY(uint   uTextFontSize READ GetTipsFontSize WRITE SetTipsFontSize)  //Prompt font size
    Q_PROPERTY(QFont  fTextFontObjs READ GetTipsFontObjs WRITE SetTipsFontObjs)  //Prompt text font object
    Q_PROPERTY(uint   uDockAlignVal READ GetDockAlignment WRITE SetDockAlignment)//Docking location index
    Q_PROPERTY(double dRadiusValues READ GetTipRadiusVal WRITE SetTipRadiusVal)  //Tip fillet scale, 0-0.5. 0
    Q_PROPERTY(QColor cBkgColorsVal READ GetTipsBkgColor WRITE SetTipsBkgColor)  //Prompt background color
    Q_PROPERTY(QColor cArrowsColors READ GetTipArrowsBkg WRITE SetTipArrowsBkg)  //Prompt arrow background color
    Q_PROPERTY(QColor cTextColorVal READ GetTipsColorVal WRITE SetTipsColorVal)  //Prompt text color
    Q_PROPERTY(bool   bShowToolTips READ GetIsShowTooltip WRITE SetIsShowTooltip)//Show reminder
public:
    Lncf_NavIndexPanel(QWidget *parent = nullptr,uint uAlignment=0);
    ~Lncf_NavIndexPanel();
protected:
    ///Initialize control virtual function
    /// \brief InitFriendsList
    ///
    void InitSocialCtrls();

    ///Rewrite drawing system
    /// \brief paintEvent
    /// \param event
    ///
    void paintEvent(QPaintEvent *event);

    ///Override system mouse movement events
    /// \brief mouseMoveEvent
    /// \param event
    ///
    void mouseMoveEvent(QMouseEvent *event);

private:
    QPushButton            *vNavIndexsBtns[29];  //List of 29 buttons

    QVBoxLayout            *lNaviBtnLayout;      //Index button container

    QList<std::u16string>   sNaviTextsList;      //Index button text

    bool                    bHasInitialize = false;      //Initialize

    bool                    bIsShowTooltip = true;       //Show reminder

    uint                    uDockAlignment = 0;  //Docking position, 0 left, 1 right

    Lncf_QTooltipFrame      *pToolTipsFrame = nullptr;
    QGraphicsDropShadowEffect *pToolTipShadow = nullptr;

public:

    ///Get the docking position index, 0 to the left, 1 to the right
    /// \brief GetDockAlignment
    /// \return
    ///
    uint GetDockAlignment() const;

    ///Get reminder font size
    /// \brief GetTipsFontSize
    /// \return
    ///
    uint GetTipsFontSize() const;

    ///Get reminder text font object
    /// \brief GetTipsFontObjs
    /// \return
    ///
    QFont GetTipsFontObjs() const;

    ///Get the fillet scale of the reminder window, 0-0.5. 0
    /// \brief GetTipRadiusVal
    /// \return
    ///
    double GetTipRadiusVal() const;

    ///Get the background color of the reminder window
    /// \brief GetTipsBkgColor
    /// \return
    ///
    QColor GetTipsBkgColor() const;

    ///Get the background color of the arrow in the reminder window
    /// \brief GetTipArrowsBkg
    /// \return
    ///
    QColor GetTipArrowsBkg() const;

    ///Gets the text color of the reminder window
    /// \brief GetTipsColorVal
    /// \return
    ///
    QColor GetTipsColorVal() const;

    ///Get whether to display navigation reminder
    /// \brief GetIsShowTooltip
    /// \return
    ///
    bool GetIsShowTooltip() const;
public slots:
    ///Button to select the slot function
    /// \brief OnNavBtnActived
    /// \param button
    /// \param checked
    ///
    void OnNavBtnActived(const uint uIndex);

    ///Button click event
    /// \brief OnNavBtnClicked
    /// \param button
    ///
    void OnNavBtnClicked(QAbstractButton *button);

    ///Set the navigation character index, which cannot be less than 28, and more than 28 will not be displayed
    /// \brief SetNaviTextsList
    /// \param sList
    ///
    void SetNaviTextsList(QList<std::u16string> sList);

    ///Set selected button
    /// \brief SetSelectNavBtn
    ///\ param uIndex: selected button index 0 indicates all # buttons, 1-26 indicates letters A to Z,27 = numeric buttons
    ///
    void SetSelectNavBtn(uint uIndex);

    ///Hide reminder
    /// \brief HideTooltipFrame
    ///
    void HideTooltipFrame();

    ///Set docking position
    /// \brief SetDockAlignment
    ///\ param uAlignment docking position, 0 left, 1 right
    ///
    void SetDockAlignment(uint uAlignment);

    ///Set reminder font size
    /// \brief SetTipsFontSize
    /// \param uSize
    ///
    void SetTipsFontSize(const uint uSize);

    ///Set reminder text font object
    /// \brief SetTipsFontObjs
    /// \param fObj
    ///
    void SetTipsFontObjs(const QFont fObj);

    ///Set the fillet scale of the reminder window, 0-0.5. 0
    /// \brief SetTipRadiusVal
    /// \param dValue
    ///
    void SetTipRadiusVal(const double dValue);

    ///Set the background color of the reminder window
    /// \brief SetTipsBkgColor
    /// \param cValue
    ///
    void SetTipsBkgColor(const QColor cValue);

    ///Set the background color of the arrow in the reminder window
    /// \brief SetTipArrowsBkg
    /// \param cValue
    ///
    void SetTipArrowsBkg(const QColor cValue);

    ///Set the text color of the reminder window
    /// \brief SetTipsColorVal
    /// \param cValue
    ///
    void SetTipsColorVal(const QColor cValue);

    ///Set whether to display navigation reminder
    /// \brief SetIsShowTooltip
    /// \param bValue
    ///
    void SetIsShowTooltip(const bool &bValue);
private:
    ///Display prompt button
    /// \brief ShowToolTipsWnd
    /// \param uIndex
    ///
    void ShowToolTipsWnd(uint uIndex);
signals:
    ///Button selected event
    /// \brief NavBtnCheckEvts
    ///\ param uIndex: selected button index 0 indicates all # buttons, 1-26 indicates letters A to Z,27 = numeric buttons
    ///
    void NavBtnCheckEvts(const uint uIndex);

The comments in the code are very clear, so they will not be repeated in the article. You can understand the meaning by looking at the code

Next, implement the vertical navigation bar. The code is as follows

Lncf_NavIndexPanel::Lncf_NavIndexPanel(QWidget *parent,uint uAlignment) : QFrame(parent)
{
    uDockAlignment = uAlignment;
    this->InitSocialCtrls();
}

Lncf_NavIndexPanel::~Lncf_NavIndexPanel()
{

}

///Initialize control virtual function
/// \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) //realization
{
    //Very important, the following code will make the Qss settings available to this class
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    QFrame::paintEvent(event);
}

///Override system mouse movement events
/// \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);
}

///Get control information
/// \brief GetSocialCtlInfo
/// \return
///
LNCFQT_SOCIALCTL_INF Lncf_NavIndexPanel::GetSocialCtlInfo()
{
    return {typeid (this).name(),tr("Social Navigate Index Frame Control")};
}

///Get navigation character index
/// \brief GetNaviTextsList
/// \return
///
QList<std::u16string> Lncf_NavIndexPanel::GetNaviTextsList() const
{
    return this->sNaviTextsList;
}

///Get the docking position index, 0 to the left, 1 to the right
/// \brief GetDockAlignment
/// \return
///
uint Lncf_NavIndexPanel::GetDockAlignment() const
{
    return this->uDockAlignment;
}

///Get reminder font size
/// \brief GetTipsFontSize
/// \return
///
uint Lncf_NavIndexPanel::GetTipsFontSize() const
{
    return pToolTipsFrame?pToolTipsFrame->GetTipsFontSize():0;
}

///Get reminder text font object
/// \brief GetTipsFontObjs
/// \return
///
QFont Lncf_NavIndexPanel::GetTipsFontObjs() const
{
    return pToolTipsFrame?pToolTipsFrame->GetTextFontObjs():QFont();
}

///Get the fillet scale of the reminder window, 0-0.5. 0
/// \brief GetTipRadiusVal
/// \return
///
double Lncf_NavIndexPanel::GetTipRadiusVal() const
{
    return pToolTipsFrame?pToolTipsFrame->GetRadiusValues():0;
}

///Get the background color of the reminder window
/// \brief GetTipsBkgColor
/// \return
///
QColor Lncf_NavIndexPanel::GetTipsBkgColor() const
{
    return pToolTipsFrame?pToolTipsFrame->GetBkgColorsVal():QColor();
}

///Get the background color of the arrow in the reminder window
/// \brief GetTipArrowsBkg
/// \return
///
QColor Lncf_NavIndexPanel::GetTipArrowsBkg() const
{
    return pToolTipsFrame?pToolTipsFrame->GetArrowsColors():QColor();
}

///Gets the text color of the reminder window
/// \brief GetTipsColorVal
/// \return
///
QColor Lncf_NavIndexPanel::GetTipsColorVal() const
{
    return pToolTipsFrame?pToolTipsFrame->GetTextColorVal():QColor();
}

///Get whether to display navigation reminder
/// \brief GetIsShowTooltip
/// \return
///
bool Lncf_NavIndexPanel::GetIsShowTooltip() const
{
    return this->bIsShowTooltip;
}

///Button to select the slot function
/// \brief OnNavBtnActived
/// \param button
/// \param checked
///
void Lncf_NavIndexPanel::OnNavBtnActived(const uint uIndex)
{
    //Implement button activation function
}

///Button click event
/// \brief OnNavBtnClicked
/// \param button
///
void Lncf_NavIndexPanel::OnNavBtnClicked(QAbstractButton *button)
{
    //Implementation button selected function
}

///Set navigation character index
/// \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;
}

///Set selected button
/// \brief SetSelectNavBtn
///\ param uIndex: selected button index 0 indicates all # buttons, 1-26 indicates letters A to Z,27 = numeric buttons
///
void Lncf_NavIndexPanel::SetSelectNavBtn(uint uIndex)
{
    if(uIndex>=0&&uIndex<29)
    {
        vNavIndexsBtns[uIndex]->setChecked(true);
    }
}

///Hide reminder
/// \brief HideTooltipFrame
///
void Lncf_NavIndexPanel::HideTooltipFrame()
{
    if(pToolTipsFrame) pToolTipsFrame->hide();
}

///Set docking position
/// \brief SetDockAlignment
///\ param uAlignment docking position, 0 left, 1 right
///
void Lncf_NavIndexPanel::SetDockAlignment(uint uAlignment)
{
    if(uAlignment>=0&&uAlignment<2){
        uDockAlignment=uAlignment;
        if(pToolTipsFrame)
        {
            //0 left, 1 right, 2 up, 3 down
            pToolTipsFrame->SetDockAlignVal(uAlignment==0?1:0);
        }
    }
}

///Set reminder font size
/// \brief SetTipsFontSize
/// \param uSize
///
void Lncf_NavIndexPanel::SetTipsFontSize(const uint uSize)
{
    if(pToolTipsFrame)pToolTipsFrame->SetTipsFontSize(uSize);
}

///Set reminder text font object
/// \brief SetTipsFontObjs
/// \param fObj
///
void Lncf_NavIndexPanel::SetTipsFontObjs(const QFont fObj)
{
    if(pToolTipsFrame)pToolTipsFrame->SetTextFontObjs(fObj);
}

///Set the fillet scale of the reminder window, 0-0.5. 0
/// \brief SetTipRadiusVal
/// \param dValue
///
void Lncf_NavIndexPanel::SetTipRadiusVal(const double dValue)
{
    if(pToolTipsFrame)pToolTipsFrame->SetRadiusValues(dValue);
}

///Set the background color of the reminder window
/// \brief SetTipsBkgColor
/// \param cValue
///
void Lncf_NavIndexPanel::SetTipsBkgColor(const QColor cValue)
{
    if(pToolTipsFrame)pToolTipsFrame->SetBkgColorsVal(cValue);
}

///Set the background color of the arrow in the reminder window
/// \brief SetTipArrowsBkg
/// \param cValue
///
void Lncf_NavIndexPanel::SetTipArrowsBkg(const QColor cValue)
{
    if(pToolTipsFrame)pToolTipsFrame->SetArrowsColors(cValue);
}

///Set the text color of the reminder window
/// \brief SetTipsColorVal
/// \param cValue
///
void Lncf_NavIndexPanel::SetTipsColorVal(const QColor cValue)
{
    if(pToolTipsFrame)pToolTipsFrame->SetTextColorVal(cValue);
}

///Set whether to display navigation reminder
/// \brief SetIsShowTooltip
/// \param bValue
///
void Lncf_NavIndexPanel::SetIsShowTooltip(const bool &bValue)
{
    this->bIsShowTooltip = bValue;
}

///Display prompt button
/// \brief ShowToolTipsWnd
/// \param uIndex
///
void Lncf_NavIndexPanel::ShowToolTipsWnd(uint uIndex)
{
/*Here, you can use QtoolTip or other customized prompt components to realize the prompt displayed when the mouse moves up*/
}

Due to the author's limited time, we will stop here first. In the next article, we will give the packaging code and description of pane navigation and ListView.

PS: welcome to join the group: 717743458

PPS: the group is new, so members can be described as scarce

Topics: C++ Qt listview