我正在尝试学习QML,以便能够创建智能手机应用程序。现在,我正在尝试创建一个列表,其中每个项目都应该是“可滑动的”,这就是我想要的:当您抓取一个列表项目时,应该可以将其向左拖动(以显示下面的菜单),然后实际列表项应该不会完全消失的左侧边缘,但还是有点可见这样你就可以将其拖回。尽可能简单的解决方案将不胜感激:)!
这是我的开始(仅使最后一个矩形可滑动):
import QtQuick 2.0
Rectangle {
width: 360
height: 360
Column {
spacing: 5
Rectangle {
color: "green"
width: 360
height: 360/3
}
Rectangle {
color: "red"
width: 360
height: 360/3
}
Flickable{
interactive: true
boundsBehavior: Flickable.StopAtBounds
contentHeight: flickme.height
contentWidth: flickme.width
width: 360
height: 360/3
Rectangle {
id:flickme
color: "yellow"
width: 360
height: 360/3
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个创建“点”并计算它们之间距离的小类。我首先创建两个“点”对象,然后将第二个作为参数传递给第一个点中包含的函数。这使我可以访问第二个点的坐标,但是我真的不知道我应该如何获得第一个点的坐标 - 接收第二个点作为参数的点。我认为它看起来像这样,但显然不是:
class Punkt{ //"Punkt" = swedish for "dot"
private:
int x, y;
public:
//Konstruktor
Punkt(int firstX, int firstY): x(firstX), y(firstY){};
//Setters and getters
int getX(){return x;}
void setX(int newX){x = newX;}
int getY(){return y;}
void setY(int newY){y = newY;}
//Avstånd till annan punkt
double distance(Punkt annanPunkt);
};
Run Code Online (Sandbox Code Playgroud)
#include "punkt.h"
#include <cmath>
double distance(Punkt annanPunkt){ //"annanpunkt" = "other dot"
return sqrt(pow((annanPunkt.getX() - self.getX), 2) +
pow((annanPunkt.getY() - self.getY, 2))
}
Run Code Online (Sandbox Code Playgroud) 我检查了所有的括号,看起来对我来说没问题,这是什么交易?(我在Codecademy上做Javascript课程)[随机文本在这里,因为stackoverflow希望我在文本和代码之间有更好的比例]
function StaffMember(name,discountPercent){
this.name = name;
this.discountPercent = discountPercent;
}
var sally = new StaffMember("Sally",5);
var bob = new StaffMember("Bob",10);
// Create yourself again as 'me' with a staff discount of 20%
var me = new StaffMember("Axel", 20);
var cashRegister = {
total:0,
lastTransactionAmount: 0,
add: function(itemCost){
this.total += (itemCost || 0);
this.lastTransactionAmount = itemCost;
},
scan: function(item,quantity){
switch (item){
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.23 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;
case "chocolate": …Run Code Online (Sandbox Code Playgroud)