Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
buttonwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include "buttonwidget.h"
5
6#include <QtWidgets>
7
8 //! [OpenCtor]
9 ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
10 : QWidget(parent)
11 {
12 //! [OpenCtor]
13 {
14 //![OldNotation]
15 signalMapper = new QSignalMapper(this);
16
17 QGridLayout *gridLayout = new QGridLayout(this);
18 for (int i = 0; i < texts.size(); ++i) {
19 QPushButton *button = new QPushButton(texts[i]);
20 connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map));
21 signalMapper->setMapping(button, texts[i]);
22 gridLayout->addWidget(button, i / 3, i % 3);
23 }
24
25 connect(signalMapper, &QSignalMapper::mappedString,
26 this, &ButtonWidget::clicked);
27 //![OldNotation]
28 }
29
30 {
31 //![ModernNotation]
32 QGridLayout *gridLayout = new QGridLayout(this);
33 for (int i = 0; i < texts.size(); ++i) {
34 QString text = texts[i];
35 QPushButton *button = new QPushButton(text);
36 connect(button, &QPushButton::clicked, [this, text] { clicked(text); });
37 gridLayout->addWidget(button, i / 3, i % 3);
38 }
39 //![ModernNotation]
40 }
41
42 //! [CloseBrackets]
43 }
44 //! [CloseBrackets]