select.h
#ifndef SELECT_H
#define SELECT_H
#include <qlistview.h>
#include <qstring.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qtextcodec.h>
#include <qapplication.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qptrlist.h>
#include <qimage.h>
#include <qpixmap.h>
class Form1 : public QWidget
{
public:
Form1( QWidget* parent = 0, const char* name = 0);
QLabel *pixmapLabel;
QLabel *textLabel;
QPushButton* pushButton2;
QPushButton* pushButton3;
QPushButton* pushButton1;
QListView *mw;
private:
QPixmap image0;
public slots:
void GetName( QListViewItem*);
};
#endif
select.cpp(我把main也放在这里了)
#include <select.h>
#include <qlistview.h>
#include <qstring.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qtextcodec.h>
#include <qapplication.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qptrlist.h>
#include <qimage.h>
#include <qpixmap.h>
#include <iostream.h>
static const unsigned char image0_data[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40,
0x08, 0x06, 0x00, 0x00, 0x00, 0xaa, 0x69, 0x71, 0xde, 0x00, 0x00, 0x1e,
0x99, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0xe5, 0x9b, 0x79, 0x94, 0x5c,};
Form1::Form1( QWidget* parent, const char* name )
: QWidget( parent, name )
{
QImage img;
img.loadFromData( image0_data, sizeof( image0_data ), "PNG" );
image0 = img;
pixmapLabel = new QLabel( this, "pixmapLabel1" );
pixmapLabel->setGeometry( QRect( 5, 5, 50, 50 ) );
pixmapLabel->setPixmap( image0 );
pixmapLabel->setScaledContents( TRUE );
textLabel=new QLabel(this,"textlabel");
textLabel->setGeometry( QRect( 58, 8, 200, 50 ) );
textLabel->setText( tr( "学习园地" ) );
textLabel->setFont(QFont("Song Ti",26,QFont::Bold));
pushButton1 = new QPushButton( this, "pushButton1" );
pushButton1->setGeometry( QRect( 230, 50, 91, 31 ) );
pushButton1->setText( tr("打开"));
pushButton2 = new QPushButton( this, "pushButton2" );
pushButton2->setGeometry( QRect( 230, 120, 91, 31 ) );
pushButton2->setText( tr("添加文件"));
pushButton3 = new QPushButton( this, "pushButton3" );
pushButton3->setGeometry( QRect( 230, 190, 91, 31 ) );
pushButton3->setText( tr("删除文件"));
QListView *mw = new QListView(this, "Form1");
mw->setGeometry( QRect( 0, 60, 211, 250 ) );
mw->addColumn( tr("目录"));
mw->setTreeStepSize( 20 );
QDir d;
d.setPath("/home/pangdae/study/");
d.setFilter(0x002);
const QFileInfoList* roots = d.entryInfoList();
QPtrListIterator<QFileInfo> i(*roots);
QFileInfo* fi;
while ( (fi = *i) ) {
++i;
QListViewItem * root = new QListViewItem( mw, fi->fileName() );
if ( roots->count() <= 1 )
root->setOpen( TRUE );
}
connect( mw, SIGNAL( clicked( QListViewItem* ) ), this,SLOT( GetName( QListViewItem*) ));
}
void Form1::GetName( QListViewItem* item)
{
QString Name;
Name=item->text( 0 );
cout<<Name<<endl;
}
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
app.setFont(QFont("Song Ti",12));
app.setDefaultCodec( QTextCodec::codecForName("zh_CN.GB2312") );
Form1 *form1=new Form1;
form1->show();
form1->setMinimumSize( QSize( 330, 320 ) );
form1->setMaximumSize( QSize( 330, 320 ) );
form1->setSizeIncrement( QSize( 330, 320 ) );
form1->setBaseSize( QSize( 330, 320 ) );
app.setMainWidget(form1);
return app.exec();
}