• 3320阅读
  • 0回复

Qt编写自定义控件46-树状导航栏 [复制链接]

上一主题 下一主题
离线liudianwu
 

只看楼主 倒序阅读 楼主  发表于: 2019-08-09

一、前言
树状导航栏控件是所有控件中最牛逼最经典最厉害的一个,在很多购买者中,使用频率也是最高,因为该导航控件集合了非常多的展示效果,比如左侧图标+右侧箭头+元素前面的图标设置+各种颜色设置等,全部涵盖了,代码量也比较多,该控件前后完善了三年,还提供了角标展示文字信息,纵观市面上web也好,cs架构的程序也好,这种导航条使用非常多,目前只提供了二级菜单,如果需要三级菜单需要自行更改源码才行。

二、实现的功能
* 1:设置节点数据相当方便,按照对应格式填入即可,分隔符,
* 2:可设置提示信息 是否显示+宽度
* 3:可设置行分隔符 是否显示+高度+颜色
* 4:可设置选中节点线条突出显示+颜色+左侧右侧位置
* 5:可设置选中节点三角形突出显示+颜色+左侧右侧位置
* 6:可设置父节点的 选中颜色+悬停颜色+默认颜色
* 7:可设置子节点的 选中颜色+悬停颜色+默认颜色
* 8:可设置父节点文字的 图标边距+左侧距离+字体大小+高度
* 9:可设置子节点文字的 图标边距+左侧距离+字体大小+高度
* 10:可设置节点展开模式 单击+双击+禁用

三、效果图



四、头文件代码
  1. #ifndef NAVLISTVIEW_H
  2. #define NAVLISTVIEW_H
  3. /**
  4. * 树状导航栏控件 作者:feiyangqingyun(QQ:517216493) 2018-8-15
  5. * 1:设置节点数据相当方便,按照对应格式填入即可,分隔符,
  6. * 2:可设置提示信息 是否显示+宽度
  7. * 3:可设置行分隔符 是否显示+高度+颜色
  8. * 4:可设置选中节点线条突出显示+颜色+左侧右侧位置
  9. * 5:可设置选中节点三角形突出显示+颜色+左侧右侧位置
  10. * 6:可设置父节点的 选中颜色+悬停颜色+默认颜色
  11. * 7:可设置子节点的 选中颜色+悬停颜色+默认颜色
  12. * 8:可设置父节点文字的 图标边距+左侧距离+字体大小+高度
  13. * 9:可设置子节点文字的 图标边距+左侧距离+字体大小+高度
  14. * 10:可设置节点展开模式 单击+双击+禁用
  15. */
  16. #include <QStyledItemDelegate>
  17. #include <QAbstractListModel>
  18. #include <QListView>
  19. #include <QStringList>
  20. class NavListView;
  21. class NavDelegate : public QStyledItemDelegate
  22. {
  23.     Q_OBJECT
  24. public:
  25.     NavDelegate(QObject *parent);
  26.     ~NavDelegate();
  27. protected:
  28.     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const ;
  29.     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
  30. private:
  31.     NavListView *nav;
  32.     QFont iconFont;
  33. };
  34. class NavModel : public QAbstractListModel
  35. {
  36.     Q_OBJECT
  37. public:
  38.     NavModel(QObject *parent);
  39.     ~NavModel();
  40. public:
  41.     struct TreeNode {
  42.         int level;                  //层级,父节点-1,子节点-2
  43.         bool expand;                //是否打开子节点
  44.         bool last;                  //是否末尾元素
  45.         QChar icon;                 //左侧图标
  46.         QString text;               //显示的节点文字
  47.         QString tip;                //右侧描述文字
  48.         QString parentText;         //父节点名称
  49.         QList<TreeNode *> children; //子节点集合
  50.     };
  51.     struct ListNode {
  52.         QString text;               //节点文字
  53.         TreeNode *treeNode;         //节点指针
  54.     };
  55. protected:
  56.     int rowCount(const QModelIndex &parent) const;
  57.     QVariant data(const QModelIndex &index, int role) const;
  58. private:
  59.     QList<TreeNode *> treeNode;
  60.     QList<ListNode> listNode;
  61. public Q_SLOTS:
  62.     void setItems(const QStringList &items);
  63.     void expand(const QModelIndex &index);
  64. private:
  65.     void refreshList();
  66. };
  67. #ifdef quc
  68. #if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
  69. #include <QtDesigner/QDesignerExportWidget>
  70. #else
  71. #include <QtUiPlugin/QDesignerExportWidget>
  72. #endif
  73. class QDESIGNER_WIDGET_EXPORT NavListView : public QListView
  74. #else
  75. class NavListView : public QListView
  76. #endif
  77. {
  78.     Q_OBJECT
  79.     Q_ENUMS(ExpendMode)
  80.     Q_PROPERTY(QString items READ getItems WRITE setItems)
  81.     Q_PROPERTY(bool rightIconVisible READ getRightIconVisible WRITE setRightIconVisible)
  82.     Q_PROPERTY(bool tipVisible READ getTipVisible WRITE setTipVisible)
  83.     Q_PROPERTY(int tipWidth READ getTipWidth WRITE setTipWidth)
  84.     Q_PROPERTY(bool separateVisible READ getSeparateVisible WRITE setSeparateVisible)
  85.     Q_PROPERTY(int separateHeight READ getSeparateHeight WRITE setSeparateHeight)
  86.     Q_PROPERTY(QColor separateColor READ getSeparateColor WRITE setSeparateColor)
  87.     Q_PROPERTY(bool lineLeft READ getLineLeft WRITE setLineLeft)
  88.     Q_PROPERTY(bool lineVisible READ getLineVisible WRITE setLineVisible)
  89.     Q_PROPERTY(int lineWidth READ getLineWidth WRITE setLineWidth)
  90.     Q_PROPERTY(QColor lineColor READ getLineColor WRITE setLineColor)
  91.     Q_PROPERTY(bool triangleLeft READ getTriangleLeft WRITE setTriangleLeft)
  92.     Q_PROPERTY(bool triangleVisible READ getTriangleVisible WRITE setTriangleVisible)
  93.     Q_PROPERTY(int triangleWidth READ getTriangleWidth WRITE setTriangleWidth)
  94.     Q_PROPERTY(QColor triangleColor READ getTriangleColor WRITE setTriangleColor)
  95.     Q_PROPERTY(int parentIconMargin READ getParentIconMargin WRITE setParentIconMargin)
  96.     Q_PROPERTY(int parentMargin READ getParentMargin WRITE setParentMargin)
  97.     Q_PROPERTY(int parentFontSize READ getParentFontSize WRITE setParentFontSize)
  98.     Q_PROPERTY(int parentHeight READ getParentHeight WRITE setParentHeight)
  99.     Q_PROPERTY(QColor parentBgNormalColor READ getParentBgNormalColor WRITE setParentBgNormalColor)
  100.     Q_PROPERTY(QColor parentBgSelectedColor READ getParentBgSelectedColor WRITE setParentBgSelectedColor)
  101.     Q_PROPERTY(QColor parentBgHoverColor READ getParentBgHoverColor WRITE setParentBgHoverColor)
  102.     Q_PROPERTY(QColor parentTextNormalColor READ getParentTextNormalColor WRITE setParentTextNormalColor)
  103.     Q_PROPERTY(QColor parentTextSelectedColor READ getParentTextSelectedColor WRITE setParentTextSelectedColor)
  104.     Q_PROPERTY(QColor parentTextHoverColor READ getParentTextHoverColor WRITE setParentTextHoverColor)
  105.     Q_PROPERTY(int childIconMargin READ getChildIconMargin WRITE setChildIconMargin)
  106.     Q_PROPERTY(int childMargin READ getChildMargin WRITE setChildMargin)
  107.     Q_PROPERTY(int childFontSize READ getChildFontSize WRITE setChildFontSize)
  108.     Q_PROPERTY(int childHeight READ getChildHeight WRITE setChildHeight)
  109.     Q_PROPERTY(QColor childBgNormalColor READ getChildBgNormalColor WRITE setChildBgNormalColor)
  110.     Q_PROPERTY(QColor childBgSelectedColor READ getChildBgSelectedColor WRITE setChildBgSelectedColor)
  111.     Q_PROPERTY(QColor childBgHoverColor READ getChildBgHoverColor WRITE setChildBgHoverColor)
  112.     Q_PROPERTY(QColor childTextNormalColor READ getChildTextNormalColor WRITE setChildTextNormalColor)
  113.     Q_PROPERTY(QColor childTextSelectedColor READ getChildTextSelectedColor WRITE setChildTextSelectedColor)
  114.     Q_PROPERTY(QColor childTextHoverColor READ getChildTextHoverColor WRITE setChildTextHoverColor)
  115.     Q_PROPERTY(ExpendMode expendMode READ getExpendMode WRITE setExpendMode)
  116. public:
  117.     //节点展开模式
  118.     enum ExpendMode {
  119.         ExpendMode_SingleClick = 0, //单击模式
  120.         ExpendMode_DoubleClick = 1, //双击模式
  121.         ExpendMode_NoClick = 2,     //不可单击双击
  122.     };
  123.     NavListView(QWidget *parent = 0);
  124.     ~NavListView();
  125. private:
  126.     NavModel *model;                //数据模型
  127.     NavDelegate *delegate;          //数据委托
  128.     QStringList parentItem;         //父节点数据集合
  129.     QList<QStringList> childItem;   //子节点数据
  130.     QString items;                  //节点集合
  131.     bool rightIconVisible;          //右侧图标是否显示
  132.     bool tipVisible;                //是否显示提示信息
  133.     int tipWidth;                   //提示信息宽度
  134.     bool separateVisible;           //是否显示行分隔符
  135.     int separateHeight;             //行分隔符高度
  136.     QColor separateColor;           //行分隔符颜色
  137.     bool lineLeft;                  //是否显示在左侧
  138.     bool lineVisible;               //是否显示线条
  139.     int lineWidth;                  //线条宽度
  140.     QColor lineColor;               //线条颜色
  141.     bool triangleLeft;              //是否显示在左侧
  142.     bool triangleVisible;           //是否显示三角形
  143.     int triangleWidth;              //三角形宽度
  144.     QColor triangleColor;           //三角形颜色
  145.     int parentIconMargin;           //父节点图标边距
  146.     int parentMargin;               //父节点边距
  147.     int parentFontSize;             //父节点字体大小
  148.     int parentHeight;               //父节点高度
  149.     QColor parentBgNormalColor;     //父节点正常背景色
  150.     QColor parentBgSelectedColor;   //父节点选中背景色
  151.     QColor parentBgHoverColor;      //父节点悬停背景色
  152.     QColor parentTextNormalColor;   //父节点正常文字颜色
  153.     QColor parentTextSelectedColor; //父节点选中文字颜色
  154.     QColor parentTextHoverColor;    //父节点悬停文字颜色
  155.     int childIconMargin;            //子节点图标边距
  156.     int childMargin;                //子节点边距
  157.     int childFontSize;              //子节点字体大小
  158.     int childHeight;                //子节点高度
  159.     QColor childBgNormalColor;      //子节点正常背景色
  160.     QColor childBgSelectedColor;    //子节点选中背景色
  161.     QColor childBgHoverColor;       //子节点悬停背景色
  162.     QColor childTextNormalColor;    //子节点正常文字颜色
  163.     QColor childTextSelectedColor;  //子节点选中文字颜色
  164.     QColor childTextHoverColor;     //子节点悬停文字颜色
  165.     ExpendMode expendMode;          //节点展开模式 单击/双击/禁用
  166. private slots:
  167.     void pressed(const QModelIndex &data);
  168.     void setData(const QStringList &listItems);
  169. public:
  170.     QString getItems()              const;
  171.     bool getRightIconVisible()      const;
  172.     bool getTipVisible()            const;
  173.     int getTipWidth()               const;
  174.     bool getSeparateVisible()       const;
  175.     int getSeparateHeight()         const;
  176.     QColor getSeparateColor()       const;
  177.     bool getLineLeft()              const;
  178.     bool getLineVisible()           const;
  179.     int getLineWidth()              const;
  180.     QColor getLineColor()           const;
  181.     bool getTriangleLeft()          const;
  182.     bool getTriangleVisible()       const;
  183.     int getTriangleWidth()          const;
  184.     QColor getTriangleColor()       const;
  185.     int getParentIconMargin()       const;
  186.     int getParentMargin()           const;
  187.     int getParentFontSize()         const;
  188.     int getParentHeight()           const;
  189.     QColor getParentBgNormalColor() const;
  190.     QColor getParentBgSelectedColor()const;
  191.     QColor getParentBgHoverColor()  const;
  192.     QColor getParentTextNormalColor()const;
  193.     QColor getParentTextSelectedColor()const;
  194.     QColor getParentTextHoverColor()const;
  195.     int getChildIconMargin()        const;
  196.     int getChildMargin()            const;
  197.     int getChildFontSize()          const;
  198.     int getChildHeight()            const;
  199.     QColor getChildBgNormalColor()  const;
  200.     QColor getChildBgSelectedColor()const;
  201.     QColor getChildBgHoverColor()   const;
  202.     QColor getChildTextNormalColor()const;
  203.     QColor getChildTextSelectedColor()const;
  204.     QColor getChildTextHoverColor() const;
  205.     ExpendMode getExpendMode()      const;
  206.     QSize sizeHint()                const;
  207.     QSize minimumSizeHint()         const;
  208. public Q_SLOTS:
  209.     //设置节点数据
  210.     void setItems(const QString &items);
  211.     //设置选中指定行
  212.     void setCurrentRow(int row);
  213.     //设置父节点右侧图标是否显示
  214.     void setRightIconVisible(bool rightIconVisible);
  215.     //设置提示信息 是否显示+宽度
  216.     void setTipVisible(bool tipVisible);
  217.     void setTipWidth(int tipWidth);
  218.     //设置行分隔符 是否显示+高度+颜色
  219.     void setSeparateVisible(bool separateVisible);
  220.     void setSeparateHeight(int separateHeight);
  221.     void setSeparateColor(const QColor &separateColor);
  222.     //设置线条 位置+可见+宽度+颜色
  223.     void setLineLeft(bool lineLeft);
  224.     void setLineVisible(bool lineVisible);
  225.     void setLineWidth(int lineWidth);
  226.     void setLineColor(const QColor &lineColor);
  227.     //设置三角形 位置+可见+宽度+颜色
  228.     void setTriangleLeft(bool triangleLeft);
  229.     void setTriangleVisible(bool triangleVisible);
  230.     void setTriangleWidth(int triangleWidth);
  231.     void setTriangleColor(const QColor &triangleColor);
  232.     //设置父节点 图标边距+左侧边距+字体大小+节点高度+颜色集合
  233.     void setParentIconMargin(int parentIconMargin);
  234.     void setParentMargin(int parentMargin);
  235.     void setParentFontSize(int parentFontSize);
  236.     void setParentHeight(int parentHeight);
  237.     void setParentBgNormalColor(const QColor &parentBgNormalColor);
  238.     void setParentBgSelectedColor(const QColor &parentBgSelectedColor);
  239.     void setParentBgHoverColor(const QColor &parentBgHoverColor);
  240.     void setParentTextNormalColor(const QColor &parentTextNormalColor);
  241.     void setParentTextSelectedColor(const QColor &parentTextSelectedColor);
  242.     void setParentTextHoverColor(const QColor &parentTextHoverColor);
  243.     //设置子节点 图标边距+左侧边距+字体大小+节点高度+颜色集合
  244.     void setChildIconMargin(int childIconMargin);
  245.     void setChildMargin(int childMargin);
  246.     void setChildFontSize(int childFontSize);
  247.     void setChildHeight(int childHeight);
  248.     void setChildBgNormalColor(const QColor &childBgNormalColor);
  249.     void setChildBgSelectedColor(const QColor &childBgSelectedColor);
  250.     void setChildBgHoverColor(const QColor &childBgHoverColor);
  251.     void setChildTextNormalColor(const QColor &childTextNormalColor);
  252.     void setChildTextSelectedColor(const QColor &childTextSelectedColor);
  253.     void setChildTextHoverColor(const QColor &childTextHoverColor);
  254.     //设置节点展开模式
  255.     void setExpendMode(const ExpendMode &expendMode);
  256. Q_SIGNALS:
  257.     void pressed(const QString &text, const QString &parentText);
  258.     void pressed(int index, int parentIndex);
  259.     void pressed(int childIndex);
  260. };
  261. #endif // NAVLISTVIEW_H

五、核心代码
  1. void NavDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
  2. {
  3.     painter->setRenderHint(QPainter::Antialiasing);
  4.     NavModel::TreeNode *node = (NavModel::TreeNode *)index.data(Qt::UserRole).toULongLong();
  5.     //定义变量存储区域
  6.     QRect optionRect = option.rect;
  7.     int x = optionRect.x();
  8.     int y = optionRect.y();
  9.     int width = optionRect.width();
  10.     int height = optionRect.height();
  11.     int fontSize = nav->getParentFontSize();
  12.     //父节点和子节点颜色分开设置
  13.     bool parent = (node->level == 1);
  14.     //根据不同的状态设置不同的颜色 bgColor-主背景色 textColor-主文字颜色 tipBgColor-提示信息背景颜色 tipTextColor-提示信息文字颜色
  15.     QColor bgColor, textColor, tipBgColor, tipTextColor, iconColor;
  16.     if (option.state & QStyle::State_Selected) {
  17.         bgColor = parent ? nav->getParentBgSelectedColor() : nav->getChildBgSelectedColor();
  18.         textColor = parent ? nav->getParentTextSelectedColor() : nav->getChildTextSelectedColor();
  19.         tipBgColor = parent ? nav->getParentTextSelectedColor() : nav->getChildTextSelectedColor();
  20.         tipTextColor = parent ? nav->getParentBgSelectedColor() : nav->getChildBgSelectedColor();
  21.         iconColor = parent ? nav->getParentTextSelectedColor() : nav->getChildTextSelectedColor();
  22.     } else if (option.state & QStyle::State_MouseOver) {
  23.         bgColor = parent ? nav->getParentBgHoverColor() : nav->getChildBgHoverColor();
  24.         textColor = parent ? nav->getParentTextHoverColor() : nav->getChildTextHoverColor();
  25.         tipBgColor = parent ? nav->getParentTextSelectedColor() : nav->getChildTextSelectedColor();
  26.         tipTextColor = parent ? nav->getParentBgSelectedColor() : nav->getChildBgSelectedColor();
  27.         iconColor = parent ? nav->getParentTextHoverColor() : nav->getChildTextHoverColor();
  28.     } else {
  29.         bgColor = parent ? nav->getParentBgNormalColor() : nav->getChildBgNormalColor();
  30.         textColor = parent ? nav->getParentTextNormalColor() : nav->getChildTextNormalColor();
  31.         tipBgColor = parent ? nav->getParentBgSelectedColor() : nav->getChildBgSelectedColor();
  32.         tipTextColor = parent ? nav->getParentTextSelectedColor() : nav->getChildTextSelectedColor();
  33.         iconColor = parent ? nav->getParentTextNormalColor() : nav->getChildTextNormalColor();
  34.     }
  35.     //绘制背景
  36.     painter->fillRect(optionRect, bgColor);
  37.     //绘制线条,目前限定子节点绘制,如果需要父节点也绘制则取消parent判断即可
  38.     int lineWidth = nav->getLineWidth();
  39.     if (!parent && nav->getLineVisible() && lineWidth > 0) {
  40.         if ((option.state & QStyle::State_Selected) || (option.state & QStyle::State_MouseOver)) {
  41.             //设置偏移量,不然上下部分会有点偏移
  42.             float offset = (float)lineWidth / 2;
  43.             //计算上下两个坐标点
  44.             QPointF pointTop(x, y + offset);
  45.             QPointF pointBottom(x, height + y - offset);
  46.             if (!nav->getLineLeft()) {
  47.                 pointTop.setX(width);
  48.                 pointBottom.setX(width);
  49.             }
  50.             //设置线条颜色和宽度
  51.             painter->setPen(QPen(nav->getLineColor(), lineWidth));
  52.             painter->drawLine(pointTop, pointBottom);
  53.         }
  54.     }
  55.     //绘制三角形,目前限定子节点绘制,如果需要父节点也绘制则取消parent判断即可
  56.     int triangleWidth = nav->getTriangleWidth();
  57.     if (!parent && nav->getTriangleVisible() && triangleWidth > 0) {
  58.         if ((option.state & QStyle::State_Selected) || (option.state & QStyle::State_MouseOver)) {
  59.             QFont font = iconFont;
  60.             font.setPixelSize(fontSize + triangleWidth);
  61.             painter->setFont(font);
  62.             painter->setPen(nav->getTriangleColor());
  63.             //采用图形字体中的三角形绘制
  64.             if (nav->getTriangleLeft()) {
  65.                 painter->drawText(optionRect, Qt::AlignLeft | Qt::AlignVCenter, QChar(0xf0da));
  66.             } else {
  67.                 painter->drawText(optionRect, Qt::AlignRight | Qt::AlignVCenter, QChar(0xf0d9));
  68.             }
  69.         }
  70.     }
  71.     //绘制行分隔符
  72.     if (nav->getSeparateVisible()) {
  73.         if (node->level == 1 || (node->level == 2 && node->last)) {
  74.             painter->setPen(QPen(nav->getSeparateColor(), nav->getSeparateHeight()));
  75.             painter->drawLine(QPointF(x, y + height), QPointF(x + width, y + height));
  76.         }
  77.     }
  78.     //绘制文字,如果文字为空则不绘制
  79.     QString text = node->text;
  80.     if (!text.isEmpty()) {
  81.         //文字离左边的距离+字体大小
  82.         int margin = nav->getParentMargin();
  83.         if (node->level == 2) {
  84.             margin = nav->getChildMargin();
  85.             fontSize = nav->getChildFontSize();
  86.         }
  87.         //计算文字区域
  88.         QRect textRect = optionRect;
  89.         textRect.setWidth(width - margin);
  90.         textRect.setX(x + margin);
  91.         QFont font;
  92.         font.setPixelSize(fontSize);
  93.         painter->setFont(font);
  94.         painter->setPen(textColor);
  95.         painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
  96.     }
  97.     //绘制提示信息,如果不需要显示提示信息或者提示信息为空则不绘制
  98.     QString tip = node->tip;
  99.     if (nav->getTipVisible() && !tip.isEmpty()) {
  100.         //如果是数字则将超过999的数字显示成 999+
  101.         //如果显示的提示信息长度过长则将多余显示成省略号 .
  102.         if (tip.toInt() > 0) {
  103.             tip = tip.toInt() > 999 ? "999+" : tip;
  104.         } else if (tip.length() > 2) {
  105.             tip = tip.left(2) + " .";
  106.         }
  107.         //计算绘制区域,半径取高度的四分之一
  108.         int radius = height / 4;
  109.         QRect tipRect = optionRect;
  110.         tipRect.setHeight(radius * 2);
  111.         tipRect.moveCenter(optionRect.center());
  112.         tipRect.setLeft(optionRect.right() - nav->getTipWidth() - 5);
  113.         tipRect.setRight(optionRect.right() - 5);
  114.         //设置字体大小
  115.         QFont font;
  116.         font.setPixelSize(fontSize - 2);
  117.         painter->setFont(font);
  118.         //绘制提示文字的背景
  119.         painter->setPen(Qt::NoPen);
  120.         painter->setBrush(tipBgColor);
  121.         painter->drawRoundedRect(tipRect, radius, radius);
  122.         //绘制提示文字
  123.         painter->setPen(tipTextColor);
  124.         painter->setBrush(Qt::NoBrush);
  125.         painter->drawText(tipRect, Qt::AlignCenter, tip);
  126.     }
  127.     //计算绘制图标区域
  128.     QRect iconRect = optionRect;
  129.     iconRect.setLeft(parent ? nav->getParentIconMargin() : nav->getChildIconMargin());
  130.     //设置图形字体和画笔颜色
  131.     QFont font = iconFont;
  132.     font.setPixelSize(fontSize);
  133.     painter->setFont(font);
  134.     painter->setPen(textColor);
  135.     //绘制左侧图标,有图标则绘制图标,没有的话父窗体取 + -
  136.     if (!node->icon.isNull()) {
  137.         painter->drawText(iconRect, Qt::AlignLeft | Qt::AlignVCenter, node->icon);
  138.     } else if (parent) {
  139.         if (node->expand) {
  140.             painter->drawText(iconRect, Qt::AlignLeft | Qt::AlignVCenter, QChar(0xf067));
  141.         } else {
  142.             painter->drawText(iconRect, Qt::AlignLeft | Qt::AlignVCenter, QChar(0xf068));
  143.         }
  144.     }
  145.     //绘制父节点右侧图标
  146.     iconRect.setRight(optionRect.width() - 10);
  147.     if (!(nav->getTipVisible() && !node->tip.isEmpty()) && nav->getRightIconVisible() && parent) {
  148.         if (node->expand) {
  149.             painter->drawText(iconRect, Qt::AlignRight | Qt::AlignVCenter, QChar(0xf054));
  150.         } else {
  151.             painter->drawText(iconRect, Qt::AlignRight | Qt::AlignVCenter, QChar(0xf078));
  152.         }
  153.     }
  154. }

六、控件介绍
1. 超过150个精美控件,涵盖了各种仪表盘、进度条、进度球、指南针、曲线图、标尺、温度计、导航条、导航栏,flatui、高亮按钮、滑动选择器、农历等。远超qwt集成的控件数量。
2. 每个类都可以独立成一个单独的控件,零耦合,每个控件一个头文件和一个实现文件,不依赖其他文件,方便单个控件以源码形式集成到项目中,较少代码量。qwt的控件类环环相扣,高度耦合,想要使用其中一个控件,必须包含所有的代码。
3. 全部纯Qt编写,QWidget+QPainter绘制,支持Qt4.6到Qt5.12的任何Qt版本,支持mingw、msvc、gcc等编译器,支持任意操作系统比如windows+linux+mac+嵌入式linux等,不乱码,可直接集成到Qt  Creator中,和自带的控件一样使用,大部分效果只要设置几个属性即可,极为方便。
4. 每个控件都有一个对应的单独的包含该控件源码的DEMO,方便参考使用。同时还提供一个所有控件使用的集成的DEMO。
5. 每个控件的源代码都有详细中文注释,都按照统一设计规范编写,方便学习自定义控件的编写。
6. 每个控件默认配色和demo对应的配色都非常精美。
7. 超过130个可见控件,6个不可见控件。
8. 部分控件提供多种样式风格选择,多种指示器样式选择。
9. 所有控件自适应窗体拉伸变化。
10.  集成自定义控件属性设计器,支持拖曳设计,所见即所得,支持导入导出xml格式。
11. 自带activex控件demo,所有控件可以直接运行在ie浏览器中。
12. 集成fontawesome图形字体+阿里巴巴iconfont收藏的几百个图形字体,享受图形字体带来的乐趣。
13. 所有控件最后生成一个dll动态库文件,可以直接集成到qtcreator中拖曳设计使用。
14. 目前已经有qml版本,后期会考虑出pyqt版本,如果用户需求量很大的话。

七、SDK下载
- SDK下载链接:https://pan.baidu.com/s/1A5Gd77kExm8Co5ckT51vvQ 提取码:877p
- 下载链接中包含了各个版本的动态库文件,所有控件的头文件,使用demo,自定义控件+属性设计器。
- 自定义控件插件开放动态库dll使用(永久免费),无任何后门和限制,请放心使用。
- 目前已提供26个版本的dll,其中包括了qt5.12.3 msvc2017 32+64 mingw 32+64 的。
- 不定期增加控件和完善控件,不定期更新SDK,欢迎各位提出建议,谢谢!
- widget版本(QQ:517216493)qml版本(QQ:373955953)三峰驼(QQ:278969898)。
- 涛哥的知乎专栏 Qt进阶之路 https://zhuanlan.zhihu.com/TaoQt
- 欢迎关注微信公众号【高效程序员】,C++/Python、学习方法、写作技巧、热门技术、职场发展等内容,干货多多,福利多多!
- Qt入门书籍推荐霍亚飞的《Qt Creator快速入门》《Qt5编程入门》,Qt进阶书籍推荐官方的《C++ GUI Qt4编程》。
- 强烈推荐程序员自我修养和规划系列书《大话程序员》《程序员的成长课》《解忧程序员》,受益匪浅,受益终生!  
欢迎关注微信公众号:Qt实战/Qt入门和进阶(各种开源作品、经验整理、项目实战技巧,专注Qt/C++软件开发,视频监控、物联网、工业控制、嵌入式软件、国产化系统应用软件开发) QQ:517216493  WX:feiyangqingyun  QQ群:751439350
快速回复
限100 字节
 
上一个 下一个