- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试做一个与 wpf stackpanel 等效的东西,我已经有了一个逻辑并实现了它但是宽度有问题,我不知道如何在不进入宽度循环绑定(bind)的情况下创建新组件,这是我的堆栈面板:
StackPanel.qml
import QtQuick 2.12
import QtQuick.Controls 2.12
import KiMa.Models 1.0
Item {
id:root
property var orientation : UOrientation.Horizontal
property int itemSpacing : 10
default property list<Item> pageData
Loader{
property var childs
anchors.fill: parent
id:loader
onChildsChanged: {
if(root.pageData != null){
for(var z = 0;z<root.pageData.length;++z){
root.pageData[z].parent = loader.childs
}
}
}
}
state: orientation == UOrientation.Horizontal ? "row": "col"
states: [
State {
name: "row"
PropertyChanges {
target: loader
sourceComponent : row
}
},
State{
name: "col"
PropertyChanges {
target: loader
sourceComponent : col
}
}
]
Component{
id:col
Column{
Component.onCompleted: {
childs = _col;
}
id:_col
width: parent.width
spacing: root.itemSpacing
}
}
Component{
id:row
Row{
Component.onCompleted: {
childs = _row
}
id:_row
width: parent.width
layoutDirection: Qt.RightToLeft
spacing: root.itemSpacing
}
}
}
我的方向枚举是这样的:
#ifndef UORIENTATION_H
#define UORIENTATION_H
#include<QObject>
class UOrientation
{
Q_GADGET
public:
explicit UOrientation();
enum Orientation{
Horizontal,
Vertical
};
Q_ENUM(Orientation)
};
#endif // UORIENTATION_H
用法示例应该是这样的:
StackPanel{
x: 320
height: 50
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 25
Button{
}
Button{
}
}
您需要将其添加到 main.cpp 中:
qmlRegisterUncreatableType<UOrientation>("KiMa.Models",1,0,"UOrientation","its not creatable type!");
此代码有效,如果您有任何建议我更改或您认为我犯了错误,请告诉我,我在这里看到的唯一问题是宽度绑定(bind)。
我已经尝试使用 childrenRect
但它不起作用:
width: childrenRect.width
height: childrenRect.height
注意:堆栈面板允许您将项目一个接一个地堆叠在一起,您可以将方向设置为水平或垂直,因此在 qt 中它是一列和一行,我已经做到了。
垂直一:
横向一:
最佳答案
通过设置列
的数量,您可以使用Grid
轻松地做到这一点。如果您想要一个单独的组件,您可以使用以下内容创建 StackPanel.qml:
import QtQuick 2.0
Grid {
property int orientation: Qt.Horizontal
columns: orientation === Qt.Horizontal ? -1 : 1
}
如果你想要一个可滚动的对象,你也可以使用带有 ObjectModel
的 ListView
模型。 ListView
有一个 orientation
属性。
关于c++ - Qt Quick 2/QML 中等效的 StackPanel - 宽度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56053860/
我有一个包含子 StackPanel 的 StackPanel(在后面的代码中添加)。 父堆栈面板 子堆栈面板 for (int i=1;i 如果您仅将 StackP
假设我们有一个水平方向且宽度为 100 像素的 Stackpanel。 在里面我制作了 11 个宽度为 10px 的方形 Canvas 绘图。 这意味着最后一个正方形将在 View 之外,因为它将扩展
我有两个停靠面板,每个停靠面板都有一个左侧 StackPanel。 的宽度底部 StackPanel 由 的宽度决定文字 在里面。 的宽度顶部 StackPanel 应该是 相同作为 的宽度底部 堆栈
我正在尝试创建一个 DataTamplate,它应该包含一个具有一定数量 StackPanel 的 StackPanel。
我有以下 WPF 控件 应用程序运行时看起来像这样。 问题是 - 当我的鼠标位于按钮之间时,弹出窗口已关闭。 (U、B、NB键之间的空隙) 如您所见 - Popup.IsOpen 属性绑定(bind)
有没有办法在运行时更改 StackPanel 内控件的顺序? 非常感谢, 保罗 最佳答案 stackPanel1.Children.Remove(item); stackPanel1.Children
我想在 ListBoxItem 上放一个命令。 ListBoxItem 使用由 StackPanel(包含 Image 和 TextBlock,均使用 Binding)组成的 DataTemplate
我有一个 Stackpanel 并希望项目根据其内容自动设置其大小,但项目不应自动填充 Stackpanel 的高度(但 Stackpanel 应根据最大项目具有自动高度)。我也试过 WrapPane
在这样的场景中: 是否可以拉伸(stretch)控制列表中的最后一个元素 (Element2) 以适应所有可能的空间(如 width="*")? 我被迫使用网格? 最佳答案
我对 WPF 很陌生,所以如果我遗漏了一些明显的东西,我深表歉意。我有这个模板绑定(bind)到 obs 中的项目。收藏。我试图让第二列,“测试测试......”部分具有可变宽度,填充父网格中的所有可
XAML有办法吗?说我想垂直居中对齐水平方向内的所有组件 StackPanel ? 我用下面的 XAML 达到了预期的结果: 但我需要重
对于 WPF/Silverlight 布局,使用具有大量行和列的 Grid 还是大量 Stackpanels 更好? 最佳答案 如果您需要水平和垂直排列的东西,您应该使用网格。当这些东西不需要与其他任
我试图在单击按钮时显示一个折叠的堆栈面板,但我遇到了问题,所以我尝试扭转我的想法,我能够折叠一个可见的堆栈面板。但不幸的是,我无法实现我想要的行为,在按钮单击时显示折叠的堆栈面板。到代码:D XAML
我需要用 stackpanel (框架)中的最后一个元素填充空白空间: _mainFrame
我是 WPF 的新手,我无法弄清楚一些事情。我刚开始一个新项目,我想制作一个 StackPanel,因为我在教程中看到了它。但是现在我已经实现了 StackPanel 并且出现了 2 个错误。 The
我正在尝试设置 StackPanel 的填充,但没有这样的属性。我尝试了 StackPanel.Border,但也没有这样的属性。 有什么想法吗? 最佳答案 您可以在 StackPanel 周围放置一
我正在尝试创建一个具有圆形背景的堆栈面板,它还有一个从灰色到透明的线性画笔 我用这里暴露的思路来防止裁剪 http://chriscavanagh.wordpress.com/2008/10/03/w
我是 WPF 的新手,我无法弄清楚一些事情。我刚开始一个新项目,我想制作一个 StackPanel,因为我在教程中看到了它。但是现在我已经实现了 StackPanel 并且出现了 2 个错误。 The
我试图在堆栈面板中插入多个矩形,但我不断收到错误消息“元素已经是另一个元素的子元素。”。如果我使用 Canvas ,也会发生同样的事情。 例子: List recList = new List();
我对 WPF 很陌生。我有一个使用 L2S 显示来自 SQL 数据库的数据的页面。 L2S 返回一个 DataTable,其中包含可供特定区域选择的所有可用选项。它从数据库返回的每一行都需要是一个 c
我是一名优秀的程序员,十分优秀!