1 #include "pinyinbar.h"
2
3 #include <QListView>
4 #include <QStringListModel>
5 #include <QLabel>
6 #include <QResizeEvent>
7 #include<QDebug>
8 #include <QHBoxLayout>
9 #include <QLabel>
10 #include <QDebug>
11
PinyinBar(QWidget * parent)12 PinyinBar::PinyinBar(QWidget *parent):QWidget(parent)
13
14 {
15 QHBoxLayout *phLayout = new QHBoxLayout(this);
16 phLayout->setContentsMargins(0,0,0,0);
17 phLayout->setSpacing(0);
18 phLayout->addWidget(m_pinyinLbl = new QLabel());
19 m_pinyinLbl->setStyleSheet("color: blue");
20 QListView *view = new QListView;
21 view->setSpacing(0);
22 m_model = new QStringListModel;
23 view->setModel(m_model);
24 phLayout->addWidget(view);
25 view->setFocusPolicy(Qt::NoFocus);
26 view->setFlow(QListView::LeftToRight);
27 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
28 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
29 view->setEditTriggers(QListView::NoEditTriggers);
30 view->setFixedHeight(30);
31 connect(view, &QListView::clicked, this, [=](const QModelIndex &index){
32 emit textChose(index.data().toString(), index.row());
33 });
34
35 view->setStyleSheet("border:none ; background: rgb(242, 242, 242); font: bold 20px;");
36 }
37
setStringList(const QStringList & data,const QString & spellingBuf)38 void PinyinBar::setStringList(const QStringList &data, const QString &spellingBuf)
39 {
40 m_model->setStringList(data);
41 m_pinyinLbl->setText(spellingBuf);
42 }
43
count()44 int PinyinBar::count()
45 {
46 return m_model->rowCount();
47 }
48