我试图在按下按钮时动态地将 tabButton 添加到TabBar但我花了很多时间搜索但我不知道如何添加,下面是我正在处理的代码:
我的选项卡按钮.qml
import QtQuick 2.4
import QtQuick.Controls 2.2
Item
{
property int BtnWidth:0
property int BtnHeight:0
property string BtnText: ""
property bool isChecked : false
TabButton
{
id:tabBtn
text:BtnText
width:BtnWidth
height:BtnHeight
}
}
Run Code Online (Sandbox Code Playgroud)
MainForm.qml
import QtQuick 2.4
import QtQuick.Controls 2.2
Rectangle
{
Button
{
id:button
width:100
height:100
anchors.top:parent.top
text:qStr("Add")
onClicked{
//How to add logic here to add tab in below tabBar.
}
}
TabBar
{
id:tabBar
anchors.top:button.bottom
width:500
height:500
}
}
Run Code Online (Sandbox Code Playgroud) 默认情况下,SwipeDelegate允许滑动多个项目,如下图所示:
如您所见,多次滑动项目一次打开,我一次只想要一个打开的项目,这意味着如果您打开项目#1,通过打开项目#2,项目#1应该关闭.我怎么能实现这个目标?
使用SwipeDelegate的ListView的示例代码:
ListView {
id: listView
anchors.fill: parent
delegate: SwipeDelegate {
id: delegate
text: modelData
width: parent.width
swipe.right: Rectangle {
width: parent.width
height: parent.height
Label {
text: qsTr("SOME ACTION BUTTON")
padding: 20
anchors.fill: parent
}
}
}
model: ListModel {
id: listModel
ListElement { text: "Lorem ipsum dolor sit amet" }
ListElement { text: "Curabitur sit amet risus" }
ListElement { text: "Suspendisse vehicula nisi" }
ListElement { text: "Mauris imperdiet libero" }
ListElement { text: "Sed vitae dui …Run Code Online (Sandbox Code Playgroud) 任何人都知道如何更改控件“ RoundButton”的颜色,该控件自2.1开始就存在于Qt控件中。
我尝试更改背景,但是如果我在该项目上放置“矩形”,则RoundButton会变成矩形,而我不知道要放置什么。
RoundButton {
id: roundButton
x: 243
y: 244
width: 20
height: 20
text: "ah"
wheelEnabled: false
background: Rectangle {
color: "yellow"
height: 50
width: 50
}
}
Run Code Online (Sandbox Code Playgroud) 如何在右键单击所选文本时获取QtQuick.Controls 2 * TextField的特定于OS的粘贴菜单。
这样可行:
import QtQuick.Controls 1.4
TextField
{
placeholderText: qsTr("Filter")
selectByMouse: true
}
Run Code Online (Sandbox Code Playgroud)
然后给我菜单
import QtQuick.Controls 2.2
TextField
{
placeholderText: qsTr("Filter")
selectByMouse: true
}
Run Code Online (Sandbox Code Playgroud)
右键单击不执行任何操作。
我使用的是5.9 LTS版本,并且停留了一段时间。
它既不能在手动安装5.9的Ubuntu Linux 16.04上运行,也不能在msys2上的Windows 10 mingw {32,64}上运行。
我在Android和iOS上的Qt 5.9.3上运行我的 Qt 应用程序。我想直接在 QML 文件上收听QGuiApplication::applicationStateChanged
如何使用连接侦听 QML 上的应用程序状态更改,而无需编写任何代码来从我的 C++ 类发出信号。
我想使用连接收听Qt::ApplicationState::ApplicationInactive和Qt::ApplicationState::ApplicationActive事件。在我的 QML 文件中使用类似的东西。
Connections {
target: something_but_what
onApplicationStateChanged: {
console.log("State changed", state)
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个ListView用rootModelQml 内部命名的自定义 C++ 模型初始化的。模型继承QAbstractListModel并将 a 定义QVector<customType>为私有成员以填充模型。
在 my 中,ApplicationWindow我创建了一个,Dialog在其中更改模型并调用setList()函数来更新它。这工作正常。
我还想将模型的大小连接到 aScrollView的int属性。此属性将定义childrena 的RowLayout。
问题是,当我尝试将此属性绑定到模型的大小时,应用程序崩溃了。
仅供参考,模型的所有修改都遵循 Qt 的规则。rowCount()是Q_INVOKABLE。我也尝试过使用onModelChanged处理程序,但这没有用(我在文档中检查了这个信号是在发出时modelReset()发出的,这是setList()通过内部发生的endResetModel()
我相信这是一个简单的过程(已经在我的项目中多次执行了属性绑定)但没有按预期工作。
我引用了我的项目的一些示例代码。
//main.qml
ConfiguredChannels{
id: configuredList
anchors{
left: parent.left
top: devices.bottom
right: tabs.left
bottom: parent.bottom
}
}
TabArea {
id: tabs
y: toolBar.height
x: parent.width / 8
anchors {
top: toolBar.bottom …Run Code Online (Sandbox Code Playgroud) 我只想更改 QML 按钮的背景颜色,但似乎没有简单的方法。你能告诉我一个简单的方法来改变 QML 按钮的背景颜色吗?谢谢!
更新:我搜索过的代码:
import QtQuick 2.6
import QtQuick.Controls 2.1
Button {
id: control
text: qsTr("Button")
contentItem: Text {
text: control.text
font: control.font
opacity: enabled ? 1.0 : 0.3
color: control.down ? "#17a81a" : "#21be2b"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 100
implicitHeight: 40
opacity: enabled ? 1 : 0.3
border.color: control.down ? "#17a81a" : "#21be2b"
border.width: 1
radius: 2
color: "black" // I update background color by this
}
}
Run Code Online (Sandbox Code Playgroud) 我需要为应用程序中的所有菜单添加阴影。我知道如何为一个菜单添加阴影:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.13
import QtGraphicalEffects 1.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Menu {
id: contextMenu
MenuItem {
text: "Menu item 1"
}
MenuItem {
text: "Menu item 2"
}
Menu {
id: subMenu
title: "Sub menu"
MenuItem {
text: "Sub menu item 1"
}
MenuItem {
text: "Sub menu item 2"
}
}
}
DropShadow
{
width: contextMenu.width;
height: contextMenu.height;
x: contextMenu.x
y: contextMenu.y
visible: contextMenu.visible;
source: …Run Code Online (Sandbox Code Playgroud) 我一直在尝试创建一个使用 Qt Quick Controls 2 以编程方式滚动到ScrollView底部的函数。我尝试了各种选项,但我在网上找到的大部分支持都是指 Qt Quick Controls 1,而不是 2。这就是我试过了:
import QtQuick 2.8
import QtQuick.Controls 2.4
ScrollView {
id: chatView
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: inputTextAreaContainer.top
function scrollToBottom() {
// Try #1
// chatView.contentItem.contentY = chatBox.height - chatView.contentItem.height
// console.log(chatView.contentItem.contentY)
// Try #2
// flickableItem.contentY = flickableItem.contentHeight / 2 - height / 2
// flickableItem.contentX = flickableItem.contentWidth / 2 - width / 2
// Try #3
chatView.ScrollBar.position = 0.0 // Tried also with 1.0
} …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
ListView {
delegate: MyDelegate {
MouseArea {
anchors.fill: parent
/*some other stuff*/
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于它MyDelegate包含复选框和MouseArea从中“窃取”鼠标事件。它们根本不会对鼠标事件做出反应,即无法按预期工作。
我知道propagateComposedEvents的财产MouseArea......但我必须实现所有的鼠标事件(clicked,pressed,released,...),并检查鼠标光标是否在复选框或不设置mouse.accepted相应属性。
这就是我目前对所有这些的理解。有没有更简单的方法,即能够处理未明确处理鼠标事件的区域的所有鼠标事件?例如静态文本,进度条等。