Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
10 : QWidget(parent)
11{
12 signalMapper = new QSignalMapper(this);
13
15 for (int i = 0; i < texts.size(); ++i) {
16 QPushButton *button = new QPushButton(texts[i]);
17 connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map));
19 signalMapper->setMapping(button, texts[i]);
20 gridLayout->addWidget(button, i / 3, i % 3);
21 }
22
26}
28
31 : QWidget(parent)
32{
34 for (int i = 0; i < texts.size(); ++i) {
35 QString text = texts[i];
38 gridLayout->addWidget(button, i / 3, i % 3);
39 }
40}
ButtonWidget(const QStringList &texts, QWidget *parent=nullptr)
[0]
void clicked(const QString &text)
void clicked(bool checked=false)
This signal is emitted when the button is activated (i.e., pressed down then released while the mouse...
The QGridLayout class lays out widgets in a grid.
Definition qgridlayout.h:21
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qgridlayout.h:64
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
\inmodule QtCore
void mappedString(const QString &)
void map()
This slot emits signals based on which object sends signals to it.
void setMapping(QObject *sender, int id)
Adds a mapping so that when map() is signalled from the given sender, the signal mappedInt(id) is emi...
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QPushButton
[1]
QString text
QPushButton * button
[2]
QGridLayout * gridLayout
[0]