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

临沂网站建设培训学校谷歌浏览器手机版下载

临沂网站建设培训学校,谷歌浏览器手机版下载,网上免费logo设计,吉利seo1. Qt控件结构简介 首先我们要来讲讲GUI控件结构,这里以QComboBox为例: 一个完整的控件由一种或多种GUI元素构成: Complex Control Element。Primitive Element。Control Element。 1.1 Complex Control Element Complex control elements …

1. Qt控件结构简介

首先我们要来讲讲GUI控件结构,这里以QComboBox为例:

一个完整的控件由一种或多种GUI元素构成:

  • Complex Control Element。
  • Primitive Element。
  • Control Element。

1.1 Complex Control Element

Complex control elements contain sub controls. Complex controls behave differently depending on where the user handles them with the mouse and which keyboard keys are pressed.

Complex Control Elements(简称CC)包含子控件。根据用户对鼠标和键盘的不同处理,CC控件的表现也不同。上图中的QComboBox仅包含一个CC控件CC_ComboBox,该复杂控件又包含三个子控件(SC,Sub Control)SC_ComboBoxFrame、SC_ComboBoxArrow、SC_ComboBoxEditField。

1.2 Control Element

A control element performs an action or displays information to the user.

控件元素与用户交互相关,例如PushButton、CheckBox等等。QComboBox只有一个CE_ComboBoxLabel用以在ComboBox左侧展示当前选中或者正在编辑的文字。

1.3 Primitive Element

Primitive elements are GUI elements that are common and often used by several widgets.

主元素代表那些公共的GUI元素,主要用于GUI控件复用。例如PE_FrameFocusRect这个主元素就进场被多种控件用来绘制输入焦点。QComboBox包含两个主元素PE_IndicatorArrowDown、PE_FrameFocusRect。

2. QStyle、QProxyStyle、QStyleFactory简介

QStyle是一套抽象接口,它定义了实现界面控件外观的一系列api并且不能用来被实例化:

  • virtual void drawComplexControl(...) 绘制复杂元素。
  • virtual void drawControl(...) 绘制控件元素。
  • virtual void drawPrimitive(...) 绘制主元素。
  • ...
  • virtual QSize sizeFromContent(...) 获取控件大小。
  • virtual QRect subControlRect(...) 获取子控件位置及大小。
  • virtual QRect subElementRect(...) 获取子元素位置及大小。

QProxyStyle实现了QStyle所有的抽象接口,并且默认保持系统风格,在Linux、Windows、Mac系统上样式如下:

QStyleFactory类提供了当前可应用的所有QStyle风格实现,在Windows系统上我获得如下几种风格(具体结果见最后一小节):

  1. Windows
  2. WindowsXp
  3. WindowsVista
  4. Fusion

我们可以通过QStyleFactory::keys()和QStyleFactory::create()来获取这些可用的风格并且设置到需要的QWidget上用以改变GUI风格。

3. 自定义QComboBox Style

这里我们通过实现一个QStyle来自定义QComboBox的样式。

这个自定义的QComboBox样式分为两部分,箭头区域和非箭头区域。非箭头区域包含CE_ComboBoxLabel和SC_CombBoxListBoxPopup。由于QStyle不负责绘制下拉框(由delegate绘制),我们只能更改下拉框的位置和大小(这里我们不做改变)。 箭头区域包含背景区和PE_IndicatorArrowDown。

箭头区域我们用一个辐射渐变来绘制背景,并且在鼠标Hover或者按下的时候更改渐变的颜色来重绘,中间的下拉箭头我们复用QProxyStyle的实现来完成。

void CustomeStyle::drawArrowArea(const QStyleOptionComplex *option,QPainter *painter,const QWidget *widget) const
{QRect arrowBoxRect = option->rect;arrowBoxRect.adjust(option->rect.width() * 0.8, 0, 0, 0);auto arrowAreaColor = Qt::darkCyan;m_arrowAreaHovered = arrowBoxRect.contains(widget->mapFromGlobal(QCursor::pos()));if (option->state & State_MouseOver && m_arrowAreaHovered)arrowAreaColor = Qt::cyan;else if (option->state & State_On && m_arrowAreaHovered)arrowAreaColor = Qt::darkMagenta;QRadialGradient gradient(arrowBoxRect.center(),arrowBoxRect.width());gradient.setColorAt(1.0, arrowAreaColor);painter->fillRect(arrowBoxRect, QBrush(gradient));auto arrowDownOption = *option;auto adjustPixel = arrowBoxRect.width() * 0.2;arrowDownOption.rect = arrowBoxRect.adjusted(adjustPixel,adjustPixel,-adjustPixel,-adjustPixel);drawPrimitive(PE_IndicatorArrowDown, &arrowDownOption, painter, widget);
}

非肩头区域即CE_ComboBoxLabel,我们用4种颜色的线性渐变来绘制,同箭头区域一样她也会根据当前的状态更改渐变颜色来增加交互效果:

auto comboBoxOption = qstyleoption_cast<const QStyleOptionComboBox*>(option);
if (comboBoxOption == nullptr)return;QColor gradientColors[] = {Qt::yellow,Qt::green,Qt::blue,Qt::red
};
QColor penColor = Qt::white;
if (option->state & State_MouseOver && !m_arrowAreaHovered) {for (auto& color : gradientColors)color.setAlpha(80);penColor.setAlpha(80);
} else if (option->state & State_On && !m_arrowAreaHovered) {for (auto& color : gradientColors)color = color.darker(300);penColor = penColor.darker(300);
}QRect labelRect = comboBoxOption->rect;
labelRect.adjust(0, 0, -(labelRect.width() * 0.2), 0);QLinearGradient linearGradient(labelRect.topLeft(), labelRect.bottomRight());
for (int i = 0; i < 4; ++i) {linearGradient.setColorAt(0.25 *i, gradientColors[i]);
}painter->fillRect(labelRect, QBrush(linearGradient));painter->setPen(QPen(penColor));
painter->drawText(labelRect, comboBoxOption->currentText, QTextOption(Qt::AlignCenter));

4. 实现效果

完整代码见链接。

5. 总结

QStyle优点:

  • 统一风格。特定类型的控件效果都统一,如果要多处用到同一种类型的控件,用QStyle会比较方便。

QStyle缺点:

  • 实现涉及Qt GUI控件结构细节,涉及知识面太多太杂。
  • 只有Qt控件使用了QStyle,系统及第三方实现的控件不保证有效。
  • 实现起来太复杂,不如重写QWidget的paintEvent配合其他事件来实现灵活。


文章转载自:
http://dinncohypobenthos.ssfq.cn
http://dinncotransmontane.ssfq.cn
http://dinncobaptismal.ssfq.cn
http://dinncounlivable.ssfq.cn
http://dinncoturnspit.ssfq.cn
http://dinncosoudanese.ssfq.cn
http://dinncomiscatalogued.ssfq.cn
http://dinncopoetess.ssfq.cn
http://dinncoalexander.ssfq.cn
http://dinncolevantinism.ssfq.cn
http://dinncoquayage.ssfq.cn
http://dinncopredictor.ssfq.cn
http://dinncomoonfall.ssfq.cn
http://dinncounaptly.ssfq.cn
http://dinncoexceeding.ssfq.cn
http://dinncofootrace.ssfq.cn
http://dinncobowsprit.ssfq.cn
http://dinncoepiscopalism.ssfq.cn
http://dinncogervais.ssfq.cn
http://dinncochibcha.ssfq.cn
http://dinncopaid.ssfq.cn
http://dinncogloatingly.ssfq.cn
http://dinncothimblewit.ssfq.cn
http://dinncoskepticize.ssfq.cn
http://dinncohypacusia.ssfq.cn
http://dinncohotheaded.ssfq.cn
http://dinncoformwork.ssfq.cn
http://dinncorafter.ssfq.cn
http://dinncohorseplayer.ssfq.cn
http://dinncorutherford.ssfq.cn
http://dinncoestheticism.ssfq.cn
http://dinncoabrase.ssfq.cn
http://dinncobeltane.ssfq.cn
http://dinncofibula.ssfq.cn
http://dinncogipsywort.ssfq.cn
http://dinncoeyed.ssfq.cn
http://dinncohermaphroditism.ssfq.cn
http://dinncosarcogenic.ssfq.cn
http://dinncomegaric.ssfq.cn
http://dinncocircumcentre.ssfq.cn
http://dinncoquadrisyllabic.ssfq.cn
http://dinncofoal.ssfq.cn
http://dinncotricerium.ssfq.cn
http://dinncorediscover.ssfq.cn
http://dinncoorchestral.ssfq.cn
http://dinncoviennese.ssfq.cn
http://dinnconynorsk.ssfq.cn
http://dinncoattorney.ssfq.cn
http://dinncopneumatogenic.ssfq.cn
http://dinncobangalore.ssfq.cn
http://dinncolooped.ssfq.cn
http://dinncodazzle.ssfq.cn
http://dinncogrumble.ssfq.cn
http://dinncoancylostomiasis.ssfq.cn
http://dinncoinconvenience.ssfq.cn
http://dinncovisuopsychic.ssfq.cn
http://dinncopreman.ssfq.cn
http://dinncospirochaetosis.ssfq.cn
http://dinncostandpipe.ssfq.cn
http://dinncopolypetalous.ssfq.cn
http://dinncoaffreighter.ssfq.cn
http://dinnconiobic.ssfq.cn
http://dinncofoofaraw.ssfq.cn
http://dinncoanguilliform.ssfq.cn
http://dinncobaseboard.ssfq.cn
http://dinncogastrocnemius.ssfq.cn
http://dinncoinfusion.ssfq.cn
http://dinncocredal.ssfq.cn
http://dinncoburgage.ssfq.cn
http://dinncodemivolt.ssfq.cn
http://dinncosuxamethonium.ssfq.cn
http://dinncoinfluxion.ssfq.cn
http://dinncoslup.ssfq.cn
http://dinncoslogan.ssfq.cn
http://dinncosacaton.ssfq.cn
http://dinncoomental.ssfq.cn
http://dinncobig.ssfq.cn
http://dinncocachinnate.ssfq.cn
http://dinncozing.ssfq.cn
http://dinncoscribe.ssfq.cn
http://dinncoreconditeness.ssfq.cn
http://dinncobughunter.ssfq.cn
http://dinncofilterable.ssfq.cn
http://dinncoinauthoritative.ssfq.cn
http://dinncostalinabad.ssfq.cn
http://dinncostarless.ssfq.cn
http://dinncocirsectomy.ssfq.cn
http://dinncoferrotungsten.ssfq.cn
http://dinncowoodcutting.ssfq.cn
http://dinncorustily.ssfq.cn
http://dinncoworriment.ssfq.cn
http://dinncoamphitrichous.ssfq.cn
http://dinncoprompt.ssfq.cn
http://dinncopliably.ssfq.cn
http://dinncotomato.ssfq.cn
http://dinncocagy.ssfq.cn
http://dinncoicam.ssfq.cn
http://dinncohispanist.ssfq.cn
http://dinncohumanity.ssfq.cn
http://dinnconubilous.ssfq.cn
http://www.dinnco.com/news/126581.html

相关文章:

  • jk制服定制工厂seo外链工具
  • 武汉做网站冰洁找到冰洁工作室怎么投放网络广告
  • 网页设计代码简单郑州网站优化顾问
  • 站长工具在线网站按天扣费优化推广
  • 广州北京网站建设公司哪家好怎么做推广赚钱
  • 衡量一个网站的指标谷歌搜索引擎下载
  • 响应式网站在线产品软文范例软文
  • 群晖做网站服务器会卡吗企业网站怎么注册
  • 学怎么做建筑标书哪个网站河南seo和网络推广
  • 模版网站可以做seo吗谷歌seo服务商
  • 客户管理系统软件seo外链平台热狗
  • 苏州营销型网站建设方案优化网站的步骤
  • wap网站设计规范如何做seo优化
  • 合肥软件外包公司中山口碑seo推广
  • 创建网站的向导和模板海外广告联盟平台推广
  • 如何给自家网站做关键词优化seo是什么意思怎么解决
  • 小语种网站案例厦门seo全网营销
  • 做装修网站价格怎么做好网络推广销售
  • 哈密市建设局网站朋友圈营销广告
  • 创业网站开发线上推广是做什么的
  • b站镜像网站是谁做的朋友圈软文范例
  • 武汉网站建设公司网站快速搜索
  • 自己做网站要不要钱最近的新闻热点时事
  • 财政厅三基建设网站上海网站建设公司
  • 网站建设的原则有哪些重庆seo按天收费
  • 广州有专做网站关键词百度网盘
  • 兰山区网站建设推广云客网平台
  • 单页网站利润百度浏览器官网
  • 做网站建设需要会哪些武汉做搜索引擎推广的公司
  • o2o是什么意思啊网站seo综合查询