Qt qml ListView 鼠标点击高亮,缩放等基础设置
2016-08-03 00:40
537 查看
import QtQuick 2.0
import QtQuick.Controls 2.0
Rectangle {
id: mainrec
property int widthx: 170
property int heightx:800
width: widthx; height: heightx
color: "lightgray"
Component{
id:listdelegate
Item{
id:delegateitem
width: widthx
height:widthx
Column{
Text{text:name;color:"#0000ff";font.pointSize: 14}
Text{text:number;color:"#000000";font.pointSize: 10}
Image{ width: 120; height: 120;source:img}
}
states: State {
name: "Current"
when: delegateitem.ListView.isCurrentItem
PropertyChanges { target: delegateitem; x:20;scale: 1.1}
}
transitions: Transition {
NumberAnimation { easing.type: Easing.Linear; properties: "x"; duration: 200 }
}
MouseArea {
anchors.fill: parent
onClicked:{
delegateitem.ListView.view.currentIndex = index
}
}
}
}
Component{
id:highlightrec
Rectangle{
width: widthx
height:widthx
color: "#f34b08"
radius: 5
border.width: 1
border.color: "#60f50a"
}
}
ListView{
id:listinfo
anchors.fill: parent
focus: true
highlight:highlightrec
highlightFollowsCurrentItem :true
model:listModelData
delegate:listdelegate
}
ListModel{
id:listModelData
ListElement{
name:"小明"
number:"4568467"
img:"qrc:/res/head5.png"
}
ListElement{
name:"YY"
number:"2741869"
img:"qrc:/res/head2.png"
}
ListElement{
name:"邹民兵"
number:"986153"
img:"qrc:/res/head3.png"
}
ListElement{
name:"马超"
number:"39148209"
img:"qrc:/res/head4.png"
}
ListElement{
name:"小明"
number:"4568467"
img:"qrc:/res/head5.png"
}
ListElement{
name:"YY"
number:"2741869"
img:"qrc:/res/head2.png"
}
ListElement{
name:"邹民兵"
number:"986153"
img:"qrc:/res/head3.png"
}
ListElement{
name:"马超"
number:"39148209"
img:"qrc:/res/head4.png"
}
ListElement{
name:"小明"
number:"4568467"
img:"qrc:/res/head5.png"
}
ListElement{
name:"YY"
number:"2741869"
img:"qrc:/res/head2.png"
}
ListElement{
name:"邹民兵"
number:"986153"
img:"qrc:/res/head3.png"
}
ListElement{
name:"马超"
number:"39148209"
img:"qrc:/res/head4.png"
}
}
}
import QtQuick.Controls 2.0
Rectangle {
id: mainrec
property int widthx: 170
property int heightx:800
width: widthx; height: heightx
color: "lightgray"
Component{
id:listdelegate
Item{
id:delegateitem
width: widthx
height:widthx
Column{
Text{text:name;color:"#0000ff";font.pointSize: 14}
Text{text:number;color:"#000000";font.pointSize: 10}
Image{ width: 120; height: 120;source:img}
}
states: State {
name: "Current"
when: delegateitem.ListView.isCurrentItem
PropertyChanges { target: delegateitem; x:20;scale: 1.1}
}
transitions: Transition {
NumberAnimation { easing.type: Easing.Linear; properties: "x"; duration: 200 }
}
MouseArea {
anchors.fill: parent
onClicked:{
delegateitem.ListView.view.currentIndex = index
}
}
}
}
Component{
id:highlightrec
Rectangle{
width: widthx
height:widthx
color: "#f34b08"
radius: 5
border.width: 1
border.color: "#60f50a"
}
}
ListView{
id:listinfo
anchors.fill: parent
focus: true
highlight:highlightrec
highlightFollowsCurrentItem :true
model:listModelData
delegate:listdelegate
}
ListModel{
id:listModelData
ListElement{
name:"小明"
number:"4568467"
img:"qrc:/res/head5.png"
}
ListElement{
name:"YY"
number:"2741869"
img:"qrc:/res/head2.png"
}
ListElement{
name:"邹民兵"
number:"986153"
img:"qrc:/res/head3.png"
}
ListElement{
name:"马超"
number:"39148209"
img:"qrc:/res/head4.png"
}
ListElement{
name:"小明"
number:"4568467"
img:"qrc:/res/head5.png"
}
ListElement{
name:"YY"
number:"2741869"
img:"qrc:/res/head2.png"
}
ListElement{
name:"邹民兵"
number:"986153"
img:"qrc:/res/head3.png"
}
ListElement{
name:"马超"
number:"39148209"
img:"qrc:/res/head4.png"
}
ListElement{
name:"小明"
number:"4568467"
img:"qrc:/res/head5.png"
}
ListElement{
name:"YY"
number:"2741869"
img:"qrc:/res/head2.png"
}
ListElement{
name:"邹民兵"
number:"986153"
img:"qrc:/res/head3.png"
}
ListElement{
name:"马超"
number:"39148209"
img:"qrc:/res/head4.png"
}
}
}
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include<QtQuick/QQuickView>
#include<QListWidget>
int main(int argc, char* argv[])
{
QGuiApplication coreApp(argc, argv);
// QQmlApplicationEngine qmlEngine;
// qmlEngine.load(QUrl(QLatin1String("qrc:/main.qml")));
QQuickView viwer;
viwer.setSource(QUrl("qrc:/main.qml"));
viwer.setVisible(true);
QQuickItem *rootItem = viwer.rootObject();
return coreApp.exec();
}
相关文章推荐
- Qt学习笔记之Threads和QObjects
- PyQt5每天必学之进度条效果
- PyQt5每天必学之带有标签的复选框
- PyQt5每天必学之滑块控件QSlider
- PyQt5每天必学之切换按钮
- Qt项目配置构建路径
- 用Layout实现QToolBox效果
- QT实现图片按钮(用qss切割图片,或者放三张图片)
- Qt下HBoxLayout里的按钮有重叠
- QT4(4.8.5)转QT5(5.5.0)
- QFile QDataStream QTextStream
- PyQt5教程-10-对话框
- QTableWidget
- pyqt 为长内容添加滑轮 scrollArea
- Qt Creator+MinGW+boost特殊函数的使用示例
- Qt之用QSetting读取配置文件
- TQ210学习笔记:TQ210移植qt
- pyqt5通过文本对话框打开文件
- Qt中QWS的含义及使用
- QT 5.3开发及移植 实例