dialog.h:
#ifndef DIALOG_H
#define DIALOG_H
#include
#include
#include
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
public slots:
void item_DblClicked(QTreeWidgetItem *item,int column);
private:
QTreeWidget *tree;
};
#endif // DIALOG_H
dialog.cpp:
#include "dialog.h"
#include
#include
#include
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
tree=new QTreeWidget(this);
tree->setColumnCount(2);
tree->setHeaderHidden(true);
QTreeWidgetItem *Friend=new QTreeWidgetItem(tree,QStringList(QString("舍友")));
QTreeWidgetItem *frd=new QTreeWidgetItem(Friend);
frd->setText(0,"黄老板");
frd->setIcon(0,QIcon(tr(":/zhang.jpg")));
QTreeWidgetItem *qin=new QTreeWidgetItem(Friend);
qin->setText(0,"秦狗");
qin->setIcon(0,QIcon(":/qin.jpg"));
QTreeWidgetItem *liu=new QTreeWidgetItem(Friend);
liu->setText(0,"嘉旭");
liu->setIcon(0,QIcon(":/liu.jpg"));
QTreeWidgetItem * ClassMate=new QTreeWidgetItem(tree,QStringList(QString("女票")));
QTreeWidgetItem *Ruru=new QTreeWidgetItem(QStringList(QString("如如")));
Ruru->setIcon(0,QIcon(tr(":/stu.jpg")));
ClassMate->addChild(Ruru);
QTreeWidgetItem *stranger=new QTreeWidgetItem(tree);
stranger->setText(0,"陌生人");
tree->addTopLevelItem(ClassMate);
tree->addTopLevelItem(stranger);
tree->expandAll();
connect(tree,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(item_DblClicked(QTreeWidgetItem*,int)));
this->setWindowTitle(tr("QQ"));
this->resize(230,300);
tree->resize(230,300);
this->setWindowIcon(QIcon(":/QQ.png"));
}
Dialog::~Dialog()
{
}
void Dialog::item_DblClicked(QTreeWidgetItem *item,int column)
{
QString str=item->text(column);
QMessageBox::warning(this,"你点击了ta","你喜欢\'"+str+"\'吗?",QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes);
}