View Full Version : ساخت ListView با قابلیت update
returnx
شنبه 13 اردیبهشت 1393, 23:13 عصر
چطور میشه یک List View با قابلیت update به طور مثال در هر یک ثانیه ساخت که model آن هم از Qstringlist و یا Qlist باشه!؟
من راه های مختلفی را امتحان کردم اما به نتیجه نرسیدم...
parvizwpf
یک شنبه 14 اردیبهشت 1393, 00:49 صبح
یعنی هر 1 ث آپدیت بشود؟ کدی که نوشتید میتونید بزارید؟
returnx
یک شنبه 14 اردیبهشت 1393, 01:14 صبح
اینم کد :
import QtQuick 2.0 import QtQuick.Controls 1.1
Rectangle {
id:main_window width: 360 height: 360 color: "black"
Text { id :title_txt font.pointSize: 10 text: qsTr("Wifi Detector") x: parent.width/2 - width anchors.top: parent
}
Component { id:list_view Rectangle { id: container width: 200 height: main_window.height - 45 border.width: 2 radius: 10 border.color: "yellow" color: "darkgray" ListView { id:ssid_listview height: parent.height x: 25 y: 15 boundsBehavior: Flickable.DragAndOvershootBounds
model:SSID_LIST_MODEL delegate: Rectangle { height: 25 width: 150 border.width: 2 radius: 7 opacity: 0.5 color: Qt.rgba(Math.random(1.0),Math.random(1.0),Math.ran dom(1.0)); Text {id:item_txt; text: modelData; anchors.centerIn: parent }
MouseArea {anchors.fill: parent hoverEnabled: true onClicked: {console.log("VALUE = " + item_txt.text) } onEntered:{parent.opacity=1.0 } onExited: {parent.opacity=0.5} }//End Item MouseArea }//End Item Rectangle }//End ListView }//End ListView Container Rectangle }//End Component
Loader { id: component_loader x: 30 y:40
} /* Timer { id:timer interval: 1000 running: false repeat: true onTriggered: { } }
*/ Button { id: scan_btn text: qsTr("Scan") x: 5 y :10
onClicked: { timer.start(); component_loader.sourceComponent=list_view;
} }
Button { id: exit_btn text: qsTr("Exit") x: parent.width - width y: parent.height - height onClicked: { Qt.quit(); } }
}
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "networking.h"
#include <QQmlContext>
#include <QTimer>
#include <QTime>
QStringList ssid_list_model;
networking network_module;
void update_timer_tick();
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/wifi_detector/main.qml"));
//Create Network Module Object:
viewer.rootContext()->setContextProperty("NetworkModule",&network_module);
//Create QStringlist for get Wifi SSID List:
ssid_list_model=network_module.get_wifi_available_ ssid();
viewer.rootContext()->setContextProperty("SSID_LIST_MODEL",QVariant::fromValue(ssid_list_model));
//Create Timer For Updating List:
QTimer *update_timer=new QTimer();
QObject::connect(update_timer,&QTimer::timeout,update_timer_tick);
update_timer->start(1000);
viewer.showExpanded();
return app.exec();
}
void update_timer_tick()
{
ssid_list_model=network_module.get_wifi_available_ ssid();
ssid_list_model.append(QTime::currentTime().toStri ng());
}
parvizwpf
یک شنبه 14 اردیبهشت 1393, 01:49 صبح
کدتون رو صحیح paste نکرده اید . بصورت html اومده. دوباره ویرایش کنید
amir.bakhtiari
یک شنبه 14 اردیبهشت 1393, 23:07 عصر
کدتون رو صحیح paste نکرده اید . بصورت html اومده. دوباره ویرایش کنید
درسته!مشخص بشه
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.