-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
77 lines (53 loc) · 1.84 KB
/
Copy pathmainwindow.cpp
File metadata and controls
77 lines (53 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QItemDelegate>
#include <QtDebug>
#include <QCompleter>
class ItemDelegate : public QItemDelegate{
// QAbstractItemDelegate interface
public:
// QAbstractItemDelegate interface
public:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
// auto text = index.data().toString();
// QStyleOptionButton buttonOption;
// buttonOption.rect = option.rect;
// buttonOption.text = text + "%";
// QApplication::style()->drawControl(QStyle::CE_PushButton,
// &buttonOption, painter);
QItemDelegate::paint(painter, option, index);
}
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const{
return QSize(100, 20);
}
// QAbstractItemDelegate interface
public:
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
return true;
}
};
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//ui->comboBox->setModel(ui->treeWidget->model());
//ui->comboBox->setView(ui->treeWidget);
ui->comboBox->view()->setEditTriggers(QAbstractItemView::EditTrigger::AllEditTriggers);
QStringList wordList;
wordList << "alpha" << "omega" << "omicron" << "zeta";
QCompleter *completer = new QCompleter(wordList, this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
ui->comboBox->setCompleter(completer);
ui->comboBox->setItemDelegate(new ItemDelegate);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->comboBox->showPopup();
}