我正在使用MouseArea实现手势捕捉器(向左/向右滑动).它应该在Flickable内部使用垂直flickableDirection.此外,它应该以可视堆栈顺序将鼠标事件传播到其下的其他元素.问题是,将propagateComposedEvents设置为true的子mouseArea 在完成一次单击之前阻止任何父级的轻弹.首次点击后,它正常工作.这是显示此内容的简化代码.
import QtQuick 2.4
import QtQuick.Window 2.2
Window {
id: __root
visible: true
width: 460; height: 640
Flickable {
id: mainFlickable
width: parent.width
height: parent.height
contentHeight: column.height
flickableDirection: Flickable.VerticalFlick
MouseArea {
anchors.fill: parent
propagateComposedEvents: true
z: 1
}
Column {
id: column
width: parent.width
Repeater {
model: 5
Rectangle {
width: __root.width
height: 200
color: "yellow"
border.width: 2
MouseArea {
anchors.fill: parent
onClicked: {
console.log("clicked")
}
}
}
} //repeater
} //column
} //flickable
} …
Run Code Online (Sandbox Code Playgroud) 所以我有 QFormLayout 可以很好地管理我的 QLabel-QLineEdit 对。
问题是,我需要实现这样的目标:
水平边框/标题不是问题,但“街道”-“公寓”/“邮政编码”-“城市”对是。
所以我的问题是:如何将两对 QLabel-QLineEdit 作为一行添加到 QFromLayout?
如果 QFormLayout 无法实现,您对其他布局(我猜是 QGridLayout)有什么建议吗?
请记住,标签在翻译成其他语言后可以具有不同的大小比例。
提前致谢!
我ShaderEffect
在 QML 中使用一些项目的缩放视觉副本。这个副本应该是可移动的和动态的(live
属性ShaderEffectSource
设置为true
)。
我的问题是我希望它在一个圆形内,Rectangle
但它不会被它剪掉。ShaderEffect
只是与它的父对象重叠并且是二次的。
我编写了一个快速 QML 示例来显示问题:
import QtQuick 2.4
import QtQuick.Controls 1.3
ApplicationWindow {
title: qsTr("Hello Shaders")
width: 640
height: 480
visible: true
color: "green"
Rectangle {
id: exampleRect
property bool redState: false
anchors.centerIn: parent
width: parent.width / 3
height: parent.height / 3
color: redState ? "red" : "cyan"
Rectangle {
anchors.centerIn: parent
width: parent.width / 2; height: width;
color: "white"
Rectangle {
anchors.centerIn: parent
width: parent.width …
Run Code Online (Sandbox Code Playgroud) 我有自定义委托,可以将其作为扩展名QListView
打开。QMenu
我已经成功地让它工作了,但是现在QMenu
openQListView
不再有焦点了。
有没有办法QListView
共享QMenu
鼠标焦点,以便可以同时滚动菜单和列表?
考虑以下代码:
int main()
{
int *intArPtr = new int[100];
int *intArPtr1 = intArPtr + 1;
delete [] intArPtr; //ok
//delete intArPtr; //valgrind warning, but no leaks!
//delete intArPtr1; //invalid pointer error
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我知道这delete [] intArPtr
是删除这个数组的唯一有效方法,但我只是对以下内容感到好奇:
delete intArPtr
不产生任何内存泄漏?是不确定的行为,我很幸运没有任何?delete intArPtr1
在运行时出错?为什么不首先从数组中删除所有元素?我希望能够Flickable
使用鼠标滚轮(或触摸板上的两根手指)滚动,而不更改它可能包含的Slider
内容。
示例代码及结果应用:
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
ApplicationWindow {
id: rootWindow
visible: true
width: 400
height: 200
title: qsTr("Hello World")
ScrollView {
anchors.fill: parent
flickableItem.flickableDirection: Flickable.VerticalFlick
Column {
Repeater {
model: 40
Slider {
width: rootWindow.width * 0.9
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
看起来过去曾尝试修复此问题,但没有成功。
编辑:这仅涉及Controls 1.x
,因为从 2.0 版本开始,控件似乎没有这个问题。
所以我知道在C++中将变量标记为未使用的两种方法:
首先(在函数体内)
void func1(int i, int unused) {
(void)unused; //marking 'unused' here
i++;
}
Run Code Online (Sandbox Code Playgroud)
和类似的
第二个(在函数的参数列表中)
void func2(int i, int /* marking 'unused' here */ ) {
i++;
}
Run Code Online (Sandbox Code Playgroud)
在我看来,第二个更好,因为它:
此外,为这两个函数生成的汇编代码是相同的(使用gcc 4.9.2测试),因此它也不是关于性能权衡.
鉴于此,我的问题是:为什么使用第一个这么常见?