PDA

View Full Version : 5 QlineEdits - 1 Button => How to copy text with less steps?



"BumbleBee"
27th November 2011, 08:53
So I have a form with some text fields(with text inside..) and a "Copy" button,which currently works as QLineEdit1 > text > copy.
The program itself is a kind of shortcut,I mean instead of having a notepad with notes and hover each line then copy it,I made some fields to hold these notes and I want to make it as simple(very few steps)as possible to use(the text: copy,insert...).

So,I don't want to make 10 btns for each text box and use the sender() function...
What are some better ways to do it?For example double-click the text in any lineedit and it copies?Or something like that.
Thanks

Lykurg
27th November 2011, 09:08
I would go for one line edit one button. That is the most intuitive approach. And you don't need to use sender or something like that for it. Just make your own widget containing the line edit and the button. In your main application just create x times that custom widget.

"BumbleBee"
27th November 2011, 14:50
How can I create that widget?
And also lets say I have lineE1 + btn1 and the button copies text from lE1.
If I paste the widget some times,the name remain same,so everything will be upside-down..or?

Lykurg
27th November 2011, 15:10
Create it by subclass QWidget. And as for the number, just introduce a private member with a setter function.

"BumbleBee"
29th November 2011, 07:19
How can I also double click the text inside and it copies?

Lykurg
29th November 2011, 18:57
Just reimplement the double click event handler of the line edit.

"BumbleBee"
4th December 2011, 08:17
Can I have some more info(maybe examples) on QWidget subclassing?
Thanks

Lykurg
4th December 2011, 08:35
The examples are full of subclassed widgets. If you make a new application your main class is a subclass of QMainWindow...
class MyClass : public QWidget
{
Q_OBJECT
public:
//...
};