teamleadersdialog.cpp

来自「QT4 gui programming的随书光盘」· C++ 代码 · 共 57 行

CPP
57
字号
#include <QtGui>#include "teamleadersdialog.h"TeamLeadersDialog::TeamLeadersDialog(const QStringList &leaders,                                     QWidget *parent)    : QDialog(parent){    model = new QStringListModel(this);    model->setStringList(leaders);    listView = new QListView;    listView->setModel(model);    listView->setEditTriggers(QAbstractItemView::AnyKeyPressed                              | QAbstractItemView::DoubleClicked);    buttonBox = new QDialogButtonBox();    QPushButton *insertButton = buttonBox->addButton(tr("&Insert"),            QDialogButtonBox::ActionRole);    QPushButton *deleteButton = buttonBox->addButton(tr("&Delete"),            QDialogButtonBox::ActionRole);    buttonBox->addButton(QDialogButtonBox::Ok);    buttonBox->addButton(QDialogButtonBox::Cancel);    connect(insertButton, SIGNAL(clicked()), this, SLOT(insert()));    connect(deleteButton, SIGNAL(clicked()), this, SLOT(del()));    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));    QVBoxLayout *mainLayout = new QVBoxLayout;    mainLayout->addWidget(listView);    mainLayout->addWidget(buttonBox);    setLayout(mainLayout);    setWindowTitle(tr("Team Leaders"));}QStringList TeamLeadersDialog::leaders() const{    return model->stringList();}void TeamLeadersDialog::insert(){    int row = listView->currentIndex().row();    model->insertRows(row, 1);    QModelIndex index = model->index(row);    listView->setCurrentIndex(index);    listView->edit(index);}void TeamLeadersDialog::del(){    model->removeRows(listView->currentIndex().row(), 1);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?