StupidBeauty
Read times:341Posted at:Wed Feb 1 18:32:33 2012
- no title specified

Wt3.2.0文档翻译:Wt::WMenu类参考,Wt::WMenu Class Reference

详细描述

这個部件显示出一個具有多个选项的菜单。

WMenu部件提供咯菜单的导航功能。

一般情况下,菜单是与WStackedWidget一同(也可以不一起使用)使用的,WStackedWidget中的不同‘内容’會堆叠在一起。菜单中的每个选项(实现为一個WMenuItem)都对应着内容堆栈中的一個标签页。内容堆栈可能會包含其它元素(items),也可能被其它WMenu实例共享。

如果没有与内容堆栈同时使用,则妳可以通过itemSelected()信号来对菜单条目的选择进行响应,以便实现对于条目选择情况的自行处理。

使用示例:

//创建内容堆栈,内容會放置在这里

Wt::WStackedWidget *contents = new Wt::WStackedWidget(contentsParent);

//创建菜单

Wt::WMenu *menu = new Wt::WMenu(contents, Wt::Vertical, menuParent);

menu->setRenderAsList(true);

//使用默认的懒加载策略来添加四個条目。

menu->addItem("Introduction", new Wt::WText("intro"));

menu->addItem("Download", new Wt::WText("Not yet available"));

menu->addItem("Demo", new DemoWidget());

menu->addItem(new Wt::WMenuItem("Demo2", new DemoWidget()));

历史上,菜单被实现为表格,但是现在更提倡渲染为一個列表(<ul>),因为这是一种规范的实现方式。

在构造之后,第一個条目會被选中。在任何时候,都可以使用select()来选中某個条目。

WMenu 的每個条目都可以关闭(参考WMenuItem::setCloseable(bool))。就像选择一样,在任何时候,都可以使用close()来关闭某個条目。妳可以使用itemClosed()信号来对条目的关闭动作进行响应。

WMenu 的实现代码中提供咯详细的控制功能,可控制那些内容是如何被预加载的。默认情况下,所有的内容都是懒加载的,只會在需要的时候加载。要想提升响应时间的话,也可以将某個条目预加载(使用addItem())。在那种情况下,那個条目會在它第一次被使用之前在后台加载。在任何情况下,一旦对应于某個菜单条目的内容被加载咯,则后续的导航操作都是在客户端处理的。

WMenu可以影响(participate)程序的内部路径,那样就能让菜单条目与内部URL对应起来,参考setInternalPathEnabled()

菜单的布局可以是水平的(Horizontal)或竖直的(Vertical)。条目的外观可通过样式单来定义。默认的WMenuItem实现代码采用四种样式类来区分非活跃的(inactivated)、活跃的(activated)、可关闭的非活跃的(closeable inactivated)和可关闭的活跃的(closeable activated)菜单条目:"item"、"itemselected"、"citem"、"citemselected"。通过使用CSS 嵌套选择器,可为不同菜单中的条目定义不同的样式。

妳可以通过特别指明(specializing)WMenuItem来对菜单条目的渲染和行为进行自定义。

CSS

取决于渲染模式(表格、列表)的不同,对菜单的样式设置也不同。按惯例,菜单都是当作列表(setRenderAsList())来进行样式设置的。

妳可以利用"item""itemselected"样式类来为未选中的和选中的条目设置不同样式,还可以利用"citem""citemselected"样式类来为未选中的和选中的可关闭条目设置不同样式。

对于不包含可关闭的条目的菜单来说,样式设置相当简单。例如,假设妳为妳的菜单设置的样式类是"menu",那麽妳可以用以下代码来设置条目的样式:

.menu * .item {

cursor: pointer; cursor: hand;

color: blue;

text-decoration: underline;

}

.menu * .itemselected {

color: blue;

text-decoration: underline;

font-weight: bold;

}

对于那些包含可关闭或/和可禁用的条目的菜单来说,样式设置會复杂一些。关闭图标由当前CSS 主题来设定,并且可被"Wt-closeicon"这個CSS 类来覆盖。(同样假设某個菜单的样式类是"menu")假设是采用WMenuItem的默认实现的话,则菜单的外观可使用以下选择器来自定义:

.Wt-closeicon : 一個关闭图标

.menu : 列表(妳的自定义菜单类)

.menu li : 一個列表条目

.menu span : 一個列表条目的区域(spans)

# 不可关闭的条目:

.menu a.item span : 一個被启用的条目的文本标签的内区域

.menu span.item : 一個被禁用的条目的文本标签

.menu a.itemselected span : 一個被启用的被选中的条目的文本标签的内区域

.menu span.itemselected : 一個被选中的禁用的条目的文本标签

# 可关闭的条目:

.menu .citem a.label span : 一個被启用的条目的文本标签的内区域

.menu .citem span.label : 一個禁用的条目的文本标签

.menu .citemselected a.label span : 一個被选中的启用的条目的文本标签的内区域

.menu .citemselected span.label : 一個被选中的禁用的条目的文本标签

示例,对于包含可关闭的条目的菜单的样式设置:

.menu {

overflow: auto;

}

.menu li {

display: inline;

}

.menu span {

display: block; float: left;

}

.menu a.item span {

cursor: pointer; cursor: hand;

color: blue;

margin-right: 5px;

}

.menu span.item {

color: gray;

margin-right: 5px;

}

.menu a.itemselected span {

color: black;

font-weight: bold;

text-decoration: none;

margin-right: 5px;

}

.menu span.itemselected {

color: gray;

font-weight: bold;

text-decoration: none;

margin-right: 5px;

}

.menu .citem a.label span {

cursor: pointer; cursor: hand;

color: blue;

}

.menu .citem span.label {

color: gray;

}

.menu .citemselected a.label span {

color: black;

font-weight: bold;

text-decoration: none;

}

.menu .citemselected span.label {

color: gray;

font-weight: bold;

text-decoration: none;

}

参考:

WMenuItem

成员函数文档

WMenuItem * Wt::WMenu::addItem

(

const WString &

name,

WWidget *

contents,

WMenuItem::LoadPolicy

policy = WMenuItem::LazyLoading

)

添加一個条目。

添加一個对应于指定的contents(内容)的菜单条目,该内容會添加到此菜单关联的内容堆栈中。

由于两个原因,contents 可能为0:

  • •.如果该菜单没有与内容堆栈关联,则妳不可将一個菜单条目与一個内容部件关联

  • •.或者,妳可能拥有一些并没有与内容堆栈中的内容部件关联的条目。

返回对应的WMenuItem

参考:

addItem(WMenuItem *)

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4