我有一个嵌套的QML窗口RowLayout
.在内排我有两个图像..png
这些图像的源文件(有意)相当大.当我尝试height
在这些图像上设置属性以使它们变小时,它们仍然被绘制得很大.
我能够让它们变小的唯一方法是设置sourceSize.height:100
而不是height:100
; 然而,这不是我想要的.我希望他们能够在不重新加载的情况下向上和向下扩展.
如何修复我的QML以使图像占据其包含的高度RowLayout
?
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
width:600; height:300
visible:true
Rectangle {
color:'red'
anchors { top:header.bottom; bottom:footer.top; left:parent.left; right:parent.right }
}
header:RowLayout {
id:header
spacing:0
height:100; width:parent.width
RowLayout {
id:playcontrol
Layout.minimumWidth:200; Layout.maximumWidth:200; Layout.preferredWidth:200
height:parent.height
Image {
// I really want these to take on the height of their row
source:'qrc:/img/play.png'
width:100; height:100
fillMode:Image.PreserveAspectFit; clip:true
}
Image …
Run Code Online (Sandbox Code Playgroud) 我正在使用SplitView
. 我希望初始空间在项目之间均匀分布,但一个项目占据了所有空间。
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 1.4
ApplicationWindow {
id:window; visible:true
width:500; height:300
title:'Borked Layouts'
SplitView {
orientation:Qt.Horizontal
anchors.fill:parent
Rectangle { color:'red'
Layout.minimumWidth:50; Layout.fillWidth:true
Layout.preferredWidth:window.width/2
}
SplitView {
orientation:Qt.Vertical
Layout.minimumWidth:50
Layout.preferredWidth:window.width/2
Rectangle { color:'green'
Layout.minimumHeight:50; Layout.fillWidth:true
}
Rectangle { color:'blue'
Layout.minimumHeight:50; Layout.fillWidth:true
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我可以拖动空格之间的分隔符来实现我想要的分布,并且尊重最小尺寸。但是我怎样才能在项目之间共享初始分布呢?
我想知道如何在QML,QT 5.7中隐藏光标.
我试着用
QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
Run Code Online (Sandbox Code Playgroud)
和
app.setOverrideCursor( QCursor( Qt::BlankCursor ) );
Run Code Online (Sandbox Code Playgroud)
但两者都不起作用.
/home/QTProjects/main.cpp:13: error: invalid use of incomplete type 'class QCursor'
QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
^
Run Code Online (Sandbox Code Playgroud)
如果有可能我可以将光标隐藏在QML中而不是C++端.
我正在开发一个 ASP.NET WebForms 应用程序,其中实体框架数据库优先与 SQL Server 连接,并且我想将相同的实体数据模型与 Oracle 数据库连接。
我的担忧是:
我试图在QML应用程序中动态构建相同类型项目的矩阵,并使它保持动态,以便您可以随时更改c ++文件中的行数和列数。这一直很好,但是现在,要单独访问它们,我想给它们提供动态名称。因此,我嵌套了两个转发器,并尝试如下设置objectName:
Repeater{
id: rows
model: Matrix1.row //number of rows in Matrix1-Object
Repeater{
id: columns
model: Matrix1.column //number of columns in Matrix1-Object
RepeatedItem{
objectName: (index) +"."+ (rows.index) //matrix elements are
supposed to be numbered x.y because of the nested repeaters, e.g.
0.0 for the first element
}
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我似乎无法访问外部索引。显示第一个值,第二个值由我的GUI的TextArea中未定义的String表示。如果我将一个新属性添加到外部Repeater并将其设置为与index相同的值,它将被设置一次并为每个重复的行保留第一个值(0)。
不可能以某种方式动态达到此外部索引值吗?还是有人知道更好的方法来动态创建可单独访问的QML项目的二维数组?
我是一名 C++ 开发人员,现在正在研究在 QtQuick 中使用 QML 进行 GUI 开发。
在创建 GUI 时,用户只能看到一个屏幕。并且基于用户交互,切换屏幕。但后面究竟发生了什么?
只有关于如何设计单个屏幕的信息很多,但关于如何管理其状态转换的资源却很少。
启动应用程序时是否加载了所有屏幕和组件并更改图层顺序以显示一次屏幕,
或者
在用户操作之后,新屏幕被构建、加载和旧屏幕被销毁(一次只有一个屏幕在内存中)
这种处理的术语是什么。
指出在哪里可以找到此类信息会很有帮助。
如果你不能理解我的问题,请告诉我。我再写一遍!!
我正在尝试使用 PuTTY 从 Windows 计算机远程在 Linux 计算机上安装 Qt。当我运行命令在 Linux 上安装 Qt 时,出现以下错误:
~/QT# ./qt-unified-linux-x64-2.0.4-online.run
QXcbConnection: Could not connect to display
Aborted
Run Code Online (Sandbox Code Playgroud)
请提出任何解决方法。
我想对应用程序中的所有文本使用本机渲染。对于每个Text
,Label
等等元素,我可以执行此操作
Text {
renderType: Text.NativeRendering
}
Run Code Online (Sandbox Code Playgroud)
触发本机渲染。我还可以在整个应用程序中使用软件渲染器:
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
Run Code Online (Sandbox Code Playgroud)
但是,由于软件渲染器存在一些错误以及一些性能问题,我想避免这种情况。
是否有全局开关可以更改渲染类型?
我开始使用QtQuick Controls 2.0。我有使用C ++的经验,也有少量使用Qt的经验,但是我以前从未使用过QML。
我有一个TabBar
和SwipeView
彼此关联的。我的意思是,当您在上选择一个页面时TabBar
,将SwipeView
转到该页面。当您从滑动到页面时SwipeView
,TabBar
更新本身会反映出来。
作为一项学习练习,我决定创建一个按钮,该按钮会将用户带到第二页。问题在于,我似乎找不到不弄乱the TabBar
和the 之间的联系的方法SwipeView
。
以下代码是我提出的最好的代码。它正确地进入到第二页,当我改变当前页面用TabBar
的SwipeView
还是更新。但是,滑动到新页面将不再更新TabBar
。似乎在对冒号进行初始化时,设置tabBar.currentIndex
为swipeView.currentIndex
仅具有通过引用进行设置的效果。用等号设置值。如何在保持不变的情况下移至特定页面swipeView.currentIndex == tabBar.currentIndex
?
// main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
SwipeView {
id: swipeView
anchors.fill: parent
currentIndex: tabBar.currentIndex
Page {
Button {
text: qsTr("Continue to Page 2")
onClicked: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此页面上指定的紫色和其他颜色,但颜色无法准确显示.
这是我的设备和linux上显示的紫色图像:
以下是默认Hello World应用程序的相关代码片段:
.pro文件:
QT += qml quick quickcontrols2
Run Code Online (Sandbox Code Playgroud)
main.cpp中:
#include <QQuickStyle>
Run Code Online (Sandbox Code Playgroud)
在 int main(int argc, char *argv[])
QQuickStyle::setStyle("Material");
main.qml:
Material.theme: Material.Dark
Material.accent: Material.Purple
Run Code Online (Sandbox Code Playgroud)