我正在使用 Qt Quick Controls 2 并为上下文菜单编写以下代码:
Menu{
id: contextmenu
x: ( parent.width - contextmenu.width ) / 2
y: ( parent.height - contextmenu.height ) / 2
modal: true
property int selid
MenuItem {
text: "Compare"
visible: isexp
}
Divider{ visible: isexp }
MenuItem {
text: "Send..."
visible: isexp
}
Divider{ visible: isexp }
MenuItem {
text: "Edit..."
}
Divider{}
MenuItem {
text: "Delete"
}
}
Run Code Online (Sandbox Code Playgroud)
分隔线 - 这是我的组件。isexp是对象的属性。当isexp false 菜单显示错误。查看截图: https ://s31.postimg.org/c608kdtbv/qqq.png
如何更改菜单项的可见性并正确显示菜单。感谢您的建议。
我正在 Qt5.7.0 QtCreator 4.1 中编写移动应用程序,我在 QtQuick qml 文件中收到错误“无效的属性名称“样式”(M16)”并且表单不想显示某些内容。我在做什么错?
我必须先在项目中配置某些内容还是使用其他类型的文件?
我尝试在某些组件上使用此属性,但它仅适用于 Text 对象,我不知道为什么。
这是我的代码:
//register_form.qml
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.1
Item {
width: 270
height: 480
anchors.fill: parent
ColumnLayout {
id: loginLayout
anchors.rightMargin: 15
anchors.bottomMargin: 92
anchors.leftMargin: 23
anchors.topMargin: 91
anchors.fill: parent
TextField {
TextFieldStyle {
id: phoneStyle
placeholderTextColor: "grey"
}
id: phoneField
placeholderText: "+7 XXX XXX XX XX"
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
}
Button {
style: //error occurs here
ButtonStyle {
}
id: …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) 我需要使用 double ,spinbox在QML view这种情况下,我基于spinbox此示例 。
SpinBox {
id: spinbox
from: 0
value: 110
to: 100 * 100
stepSize: 100
anchors.centerIn: parent
property int decimals: 2
property real realValue: value / 100
validator: DoubleValidator {
bottom: Math.min(spinbox.from, spinbox.to)
top: Math.max(spinbox.from, spinbox.to)
}
textFromValue: function(value, locale) {
return Number(value / 100).toLocaleString(locale, 'f', spinbox.decimals)
}
valueFromText: function(text, locale) {
return Number.fromLocaleString(locale, text) * 100
}
}
Run Code Online (Sandbox Code Playgroud)
似乎当您使用自定义旋转框时,它不会显示为“经典”旋转框。显示如下:
但是,按钮对于我的界面来说太大了。我想知道是否有一种简单的方法可以将旋转框显示为“经典”旋转框,如下所示:
ProgressBar{
id:progressBar
width : parent.width * 0.80
height:parent.height * 0.05
anchors.bottom:parent.bottom
anchors.bottomMargin: (parent.height * 0.03)
anchors.left:parent.left
anchors.leftMargin: (parent.width * 0.05)
value : 0.5
background: Rectangle {
color: "#e6e6e6"
radius: 3
}
contentItem: Item {
Rectangle {
width: progressBar.visualPosition * parent.width
height: parent.height
radius: 2
color: "#17a81a"
gradient: Gradient {
GradientStop {
position: 0.0
SequentialAnimation on color {
loops: Animation.Infinite
ColorAnimation { from: "#14148c"; to: "#0E1533"; duration: 5000 }
ColorAnimation { from: "#0E1533"; to: "#14148c"; duration: …Run Code Online (Sandbox Code Playgroud) 我在 QtCreator 中创建了默认的“空”qml 应用程序。然后我只需添加按钮并运行它:
import QtQuick 2.11
import QtQuick.Window 2.11
import QtQuick.Controls 2.4
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Button {
text: "Button1"
}
}
Run Code Online (Sandbox Code Playgroud)
但是按钮看起来非常丑陋:
我应该做什么(打开或添加或 smth)使它看起来更有吸引力?
例如,即使是默认的 Win10 视图也适合我。
答除了:它给我伤心,但没有办法让QtQuick应用看起来比通过自我实现所有comtrols的。下面的答案解释了如何做到这一点。
我在 Qt Creator 5.6.13 上收到错误“模块“QtQuick.Controls”版本 2.0 未安装”,所以我升级到 5.11.2 并且我仍然得到它。
这是导致它的部分:
import QtQuick.Controls 2.0
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助。
如果我使用滑动视图,我会遇到一些问题,并且我编写了以下代码:
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Swipe View")
MainForm {
anchors.fill:parent
Rectangle{
id:rightRect
anchors.right:parent.right
width: parent.width*0.50
height:parent.height
color:"yellow"
}
Rectangle{
id:leftRect
width:parent.width*0.50
height:parent.height
color:"lightgreen"
border.color:"red"
anchors.right:rightRect.left
SwipeView{
id:swipeView
anchors.fill : leftRect
//Layout.fillWidth: true
currentIndex: 0
interactive: false
Page{
id:page1
Rectangle{
width:parent.width
height:parent.height
color:"lightgreen"
Button{
text:"move to 2"
onClicked: swipeView.currentIndex = 1
}
}
}
Page{
id:page2
Rectangle{
width:parent.width
height:parent.height
color:"lightblue"
Button{
text:"move to 1"
onClicked: swipeView.currentIndex = …Run Code Online (Sandbox Code Playgroud) 我们正在使用QtQuick.Controls 2.2并且由于各种原因无法降级.当我们使用ComboboxQML中的util时,它不会出现selectByMouse在1.4版本中引入的字段.
我们的要求是 - 能够选择组合框中的文本进行复制,并有一个下拉菜单.
如何解决这个问题; 还有其他选择吗?
qml ×10
qtquickcontrols2 ×10
qt ×9
qtquick2 ×7
qt-creator ×2
c++ ×1
mouse ×1
options ×1
progress-bar ×1
qspinbox ×1
qt5 ×1