当前位置: 首页 > news >正文

做问卷赚钱网站百度推广要自己建站吗

做问卷赚钱网站,百度推广要自己建站吗,wordpress 西部数码,凭祥网站建设概述 在Qt中,可以使用样式表(StyleSheet)来自定义 QMenu 的外观,包括其子项(如菜单项QAction)的颜色。但是,这通常可以设置 QMenu 的整体样式,而不能单独设置某个子项的颜色。不过&…

概述

在Qt中,可以使用样式表(StyleSheet)来自定义 QMenu 的外观,包括其子项(如菜单项QAction)的颜色。但是,这通常可以设置 QMenu 的整体样式,而不能单独设置某个子项的颜色。不过,我们可以通过自定义的 QWidgetAction实现这一目标:

效果图

实现过程

  1. 创建一个继承自 QWidgetAction 的子类 ColorAction。
  2. 添加一个的 QWidget,在 QWidget 中添加一个 QLabel。
  3. 为这个 QLabel 设置样式表。
  4. 然后,将这个自定义的 QWidgetAction 添加到 QMenu 中。

关键代码

ColorAction 类

#pragma once#include <QWidgetAction>
#include <QWidget>
#include <QLabel>  
#include <QVBoxLayout>  
#include <QStyleOption>class ColorAction : public QWidgetAction
{Q_OBJECTpublic:ColorAction(const QString text, const int nMenuHeight, QObject *parent = nullptr);~ColorAction();private:QLabel *label;QWidget *widget;
};
#include "ColorAction.h"ColorAction::ColorAction(const QString text, const int nMenuHeight, QObject *parent /*= nullptr*/) : QWidgetAction(parent)
{// 创建一个QWidget作为容器,并设置布局  widget = new QWidget();QVBoxLayout *layout = new QVBoxLayout(widget);layout->setContentsMargins(0, 0, 0, 0);// 创建QLabel并设置文字颜色  label = new QLabel(text, widget);label->setFixedHeight(nMenuHeight);label->setFont(QFont(QString::fromLocal8Bit("微软雅黑"), 10.5));label->setStyleSheet("QLabel{ padding-left:16px; color: #ff5050;background-color: rgb(255, 255, 255);} QLabel:hover{ background-color: #e9f2ff;}");layout->addWidget(label);setDefaultWidget(widget);
}ColorAction::~ColorAction()
{
}

使用 QMenu 类

#include "QMenuColorDemo.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMouseEvent>class QPoint;QMenuColorDemo::QMenuColorDemo(QWidget *parent): QWidget(parent)
{ui.setupUi(this);	this->setFixedSize(310,200);_menu = new QMenu;_menu->setFixedWidth(115);_menu->setFont(QFont(QString::fromLocal8Bit("微软雅黑"), 10.5));int nMenuHeight = 30;_menu->setStyleSheet(QString::fromLocal8Bit("QMenu{\background:white;\border:1px solid lightgray;\padding-top:10px;\padding-bottom:10px;\}\QMenu::item{\padding:0px 20px;\height:%1px;\}\QMenu::item:selected:enabled{\background:#e9f2ff;\color:black;\}\QMenu::item:selected:!enabled{\background:transparent;\}\QMenu::separator{\height:1px;\background:#e4e4e4;\margin:5px 0px 5px 0px;\}").arg(nMenuHeight));_viewAction = new QAction(QString::fromLocal8Bit("查看"), this);_refreshAction = new QAction(QString::fromLocal8Bit("刷新"), this);_delAction = new ColorAction(QString::fromLocal8Bit("删除"), nMenuHeight, this);_menu->addAction(_viewAction);_menu->addAction(_refreshAction);_menu->addSeparator();_menu->addAction(_delAction);_btn = new QPushButton(QString::fromLocal8Bit("彩色菜单"));connect(_btn,&QPushButton::clicked,this, [=](){QPoint p = cursor().pos();_menu->exec(p);});QHBoxLayout * hLayout = new QHBoxLayout;hLayout->addWidget(_btn);hLayout->addStretch();QVBoxLayout *vLayout = new QVBoxLayout;vLayout->addItem(hLayout);vLayout->addStretch();this->setLayout(vLayout);	
}void QMenuColorDemo::mousePressEvent(QMouseEvent *event)
{if (event->button() == Qt::RightButton ){QPoint p = cursor().pos();_menu->exec(p);}
}

源码下载

https://download.csdn.net/download/qiangzi4646/89754043

http://www.hengruixuexiao.com/news/39640.html

相关文章:

  • 北京网站制作最新教程弹窗广告最多的网站
  • 上市公司网站建设ks免费刷粉网站推广
  • 手机网站支持微信支付吗百度网站推广申请
  • 做网站什么分类流量多互联网销售平台
  • 法与家国建设征文网站网店seo是什么意思
  • 接单做效果图网站网站优化及推广
  • 泉州网站公司江门关键词排名工具
  • 怎么做新网站职业培训机构需要什么资质
  • 团购网站 seo搭建一个网站平台需要多少钱
  • 社区网站制作教程小程序开发公司排行榜
  • 医院网站建设平台百度注册公司地址
  • 网站怎么做优化推广代刷网站推广快速
  • wordpress 数据库操作宁波网站seo哪家好
  • 公众号做视频网站吗云南省最新疫情情况
  • seo网站推广软件 快排网络服务提供者
  • 站长工具seo综合查询工具知乎关键词优化软件
  • 网站后台怎么做超链接东莞网站推广优化公司
  • 云网站开发东莞seo网络营销
  • 怎么做网站评估平台推广方案
  • 北京网站建设中心首页关键词排名
  • 庆阳网站哪里做粤语seo是什么意思
  • 计算机应用教程 网站的建设与维护广告网站
  • 个体户 网站建设济南网络优化厂家
  • 新浪博客上传wordpress手机网站排名优化
  • 香港公司能在大陆做网站吗seo自己怎么做
  • 旅游网站建设初衷seo相关ppt
  • 闵行网站设计seo快速排名软件平台
  • 0基础做网站工具软文平台有哪些
  • 网站推广方案书国际新闻最新消息中国
  • 衡阳做网站建设的公司西安核心关键词排名