首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

QT实现自定义侧边导航栏

移动开发 26.5KB 14 需要积分: 1
立即下载

资源介绍:

侧边导航栏是应用程序界面的一种常见布局,它通常位于页面或应用程序的侧边位置,用来展示导航菜单或功能链接,方便用户快速访问不同的页面或功能。本示例展示了在QT中,通过自定义QWidget来实现自定义的侧边导航栏。你可以根据需要修改样式、添加图标等来达到你想要的效果。
#include "qnavigationwidget.h" #include #include QNavigationWidget::QNavigationWidget(QWidget *parent) : QWidget(parent) { backgroundColor = "#E4E4E4"; selectedColor = "#2CA7F8"; mouseInColor = "#C4C4C4"; rowHeight = 40; currentIndex = 0; mouseMoveIndex = -1; setMouseTracking(true); setFixedWidth(120); } QNavigationWidget::~QNavigationWidget() { } void QNavigationWidget::addItem(const QString &iconPath,const QString &title) { listIcons << iconPath; listItems << title; update(); } void QNavigationWidget::setWidth(const int &width) { setFixedWidth(width); } void QNavigationWidget::setBackgroundColor(const QColor &color) { backgroundColor = color; update(); } void QNavigationWidget::setSelectColor(const QColor &color) { selectedColor = color; update(); } void QNavigationWidget::setMouseInColor(const QColor &color) { mouseInColor = color; update(); } void QNavigationWidget::setRowHeight(const int &height) { rowHeight = height; update(); } void QNavigationWidget::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); // Draw background color. painter.setPen(Qt::NoPen); painter.setBrush(backgroundColor); painter.drawRect(rect()); // Draw Items int count = 0; for (const QString &str : listItems) { QPainterPath itemPath; itemPath.addRect(QRect(0, count * rowHeight, width(), rowHeight)); if (currentIndex == count) { painter.setPen("#FFFFFF"); painter.fillPath(itemPath, selectedColor); } else if(mouseMoveIndex == count) { painter.setPen("#FFFFFF"); painter.fillPath(itemPath, mouseInColor); } else { painter.setPen("#202020"); painter.fillPath(itemPath, backgroundColor); } //painter.drawText(QRect(40, count * rowHeight, width()-40, rowHeight), Qt::AlignVCenter | Qt::AlignHCenter, str); painter.drawPixmap(QRect(20, (count * rowHeight+(rowHeight-20)/2), 20, 20),QPixmap(listIcons[count])); painter.drawText(QRect(45, count * rowHeight, width()-40, rowHeight), Qt::AlignVCenter, str); ++count; } } void QNavigationWidget::mouseMoveEvent(QMouseEvent *e) { if (e->y() / rowHeight < listItems.count()) { mouseMoveIndex = e->y() / rowHeight; } else { mouseMoveIndex = -1; } update(); } void QNavigationWidget::mousePressEvent(QMouseEvent *e) { if (e->y() / rowHeight < listItems.count()) { currentIndex = e->y() / rowHeight; emit currentItemChanged(currentIndex); update(); } } void QNavigationWidget::leaveEvent(QEvent *) { if(mouseMoveIndex !=-1 ) { mouseMoveIndex = -1; update(); } }

资源文件列表:

QNavigationWidget.zip 大约有15个文件
  1. QNavigationWidget/
  2. QNavigationWidget/main.cpp 177B
  3. QNavigationWidget/mainwindow.cpp 1.33KB
  4. QNavigationWidget/mainwindow.h 206B
  5. QNavigationWidget/qnavigationwidget.cpp 2.85KB
  6. QNavigationWidget/qnavigationwidget.h 969B
  7. QNavigationWidget/QNavigationWidget.pro 676B
  8. QNavigationWidget/res/
  9. QNavigationWidget/res/contents.png 6.27KB
  10. QNavigationWidget/res/editclear.png 4.42KB
  11. QNavigationWidget/res/editcopy.png 2.9KB
  12. QNavigationWidget/res/filenew.png 1.94KB
  13. QNavigationWidget/res/fileopen.png 3.08KB
  14. QNavigationWidget/res/filesave.png 3.12KB
  15. QNavigationWidget/ui.qrc 273B
0评论
提交 加载更多评论
其他资源 11111111111111111111
11111
中国生态功能保护区shp数据
中国生态功能保护区shp数据
安全高级认证HTML源码.zip
安全高级认证HTML源码.zip
CHS零壹视频恢复程序监控版
1、支持对FAT32、EXFAT 、RAW等大容量专用高速卡的扫描。 2、全面支持大华、海康、天地伟业、中维、宇视奇盾、水星、安邦、宇视、TPLINK、雄迈等超过130多个安防品牌。 3、支持碎片重组功能,程序可以快速定位碎片并自动分析重组。 4、内置CHS_SMART第二代视频重组算法,保持原始编码的同时还可以最大化重组碎片,得到原始完美的画质。 4、支持对存储介质进行镜像备份的功能。 5、可以对存储介质任意创建区域进行扫描。 6、支持查看存储介质的HEX值。 7、支持保存“扫描结果”和“加载扫描结果”。 8、支持试用播放功能。 9、支持OCR功能
jdk中文字体文件,用于linux
jdk中文字体文件,用于linux
Java描述设计模式(24):备忘录模式.zip
Java描述设计模式(24):备忘录模式
RTT 3.1.5以及MSPM0截至到2024.08.14最新pack
RTT 3.1.5以及MSPM0截至到2024.08.14最新pack
ST1633I-沁恒微CH554-IC代码
ST1633I-沁恒微CH554-IC代码