ok.
The point I made about saving the lineedit pointers in a container is valid - you should do that.
You can iterate over all the lineedits in the container and use http://qt-project.org/doc/qt-4.8/qli...ectedText-prop to find the selected text in each.
To copy text from a label into the clipboard is very simple using signal mapper. I will make a small example...
Added after 21 minutes:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
{
Q_OBJECT
public:
explicit Widget
(QWidget *parent
= 0);
~Widget();
private slots:
void slotCopyToClipboard
(QString text
) const;
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void slotCopyToClipboard(QString text) const;
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
cpp
#include "widget.h"
#include "ui_widget.h"
#include "clickablelabel.h"
#include <QClipboard>
#include <QLabel>
#include <QVBoxLayout>
#include <QTextEdit>
#include <QList>
#include <QSignalMapper>
QWidget(parent
) //ui(new Ui::Widget) {
//ui->setupUi(this);
ClickableLabel* lbl1 = new ClickableLabel("one");
ClickableLabel* lbl2 = new ClickableLabel("two");
ClickableLabel* lbl3 = new ClickableLabel("three");
QList<ClickableLabel*> labels;
labels << lbl1 << lbl2 << lbl3;
foreach(ClickableLabel* lbl, labels)
layout->addWidget(lbl);
setLayout(layout);
foreach(ClickableLabel* lbl, labels)
{
connect(lbl, SIGNAL(clicked()), sm, SLOT(map()));
sm->setMapping(lbl, lbl->text());
}
connect(sm,
SIGNAL(mapped
(QString)),
this,
SLOT(slotCopyToClipboard
(QString)));
}
Widget::~Widget()
{
}
void Widget
::slotCopyToClipboard(QString text
) const {
cb->setText(text);
}
#include "widget.h"
#include "ui_widget.h"
#include "clickablelabel.h"
#include <QClipboard>
#include <QLabel>
#include <QVBoxLayout>
#include <QTextEdit>
#include <QList>
#include <QSignalMapper>
Widget::Widget(QWidget *parent) :
QWidget(parent) //ui(new Ui::Widget)
{
//ui->setupUi(this);
QVBoxLayout* layout = new QVBoxLayout;
ClickableLabel* lbl1 = new ClickableLabel("one");
ClickableLabel* lbl2 = new ClickableLabel("two");
ClickableLabel* lbl3 = new ClickableLabel("three");
QList<ClickableLabel*> labels;
labels << lbl1 << lbl2 << lbl3;
foreach(ClickableLabel* lbl, labels)
layout->addWidget(lbl);
layout->addWidget(new QTextEdit());
setLayout(layout);
QSignalMapper* sm = new QSignalMapper(this);
foreach(ClickableLabel* lbl, labels)
{
connect(lbl, SIGNAL(clicked()), sm, SLOT(map()));
sm->setMapping(lbl, lbl->text());
}
connect(sm, SIGNAL(mapped(QString)), this, SLOT(slotCopyToClipboard(QString)));
}
Widget::~Widget()
{
}
void Widget::slotCopyToClipboard(QString text) const
{
QClipboard* cb = QApplication::clipboard();
cb->setText(text);
}
To copy to clipboard, switch view to plain text mode
clickable label from here:
http://qt-project.org/wiki/Make-a-QLabel-Clickable
Or you could use a pushbutton and make it look flat.
Just click on the label, and then right-click in the text edit and paste to confirm that the label string is in the clipboard.
Bookmarks