#include "mailclient.h"#include "ui_mailclient.h"#include#include MailClient::MailClient(QWidget *parent) : QMainWindow(parent), ui(new Ui::MailClient){ ui->setupUi(this); this->setCentralWidget(ui->splitter_2); ui->splitter_2->setStretchFactor(2,2); QIcon folderIcon(style()->standardPixmap(QStyle::SP_DirClosedIcon)); QIcon trashIcon(style()->standardPixmap(QStyle::SP_FileIcon)); QStringList labels; labels < treeWidget_2->setHeaderLabels(labels); addFolder(folderIcon,tr("Inbox")); addFolder(folderIcon,tr("Outbox")); addFolder(folderIcon,tr("Sent")); addFolder(trashIcon,tr("Trash")); QStringList messageLabels; messageLabels << tr("Subject") << tr("Sender") << tr("Date"); addMessage(tr("Hello Qt"),tr(" "),tr("2016/06/29")); addMessage(tr("Hello Qt"),tr(" "),tr("2016/06/29")); addMessage(tr("Hello Qt"),tr(" "),tr("2016/06/29")); ui->treeWidget->setHeaderLabels(messageLabels);}MailClient::~MailClient(){ delete ui;}void MailClient::addMessage(const QString &subject,const QString &from,const QString &data){ QTreeWidgetItem *newItem = new QTreeWidgetItem(ui->treeWidget); newItem->setText(0,subject); newItem->setText(1,from); newItem->setText(2,data); if(!ui->treeWidget->currentItem()) ui->treeWidget->setCurrentItem(newItem);}void MailClient::addFolder(const QIcon &icon, const QString &name){ QTreeWidgetItem *root; if(ui->treeWidget_2->topLevelItemCount()==0) { root = new QTreeWidgetItem(ui->treeWidget_2); root->setText(0,tr("Mail")); ui->treeWidget_2->setItemExpanded(root,true); } else { root = ui->treeWidget_2->topLevelItem(0); } QTreeWidgetItem *newItem = new QTreeWidgetItem(root); newItem->setText(0,name); newItem->setIcon(0,icon); if(!ui->treeWidget_2->currentItem()) ui->treeWidget_2->setCurrentItem(newItem);}
#ifndef MAILCLIENT_H#define MAILCLIENT_H#includenamespace Ui {class MailClient;}class MailClient : public QMainWindow{ Q_OBJECTpublic: explicit MailClient(QWidget *parent = 0); ~MailClient();private: Ui::MailClient *ui; void addFolder(const QIcon &icon,const QString &name); void addMessage(const QString &subject,const QString &from,const QString &data);};#endif // MAILCLIENT_H