simple questions. qt3 to qt4
Hi. I am having a great deal of trouble with some of the documentation in Qt4. I have spent a lot of time on just these 2 VERY BASIC items
Qt3: text = listBox ->text ( index ); and/or item index from QListBox. how in QListView or QListWidget or ???
Qt3: textEdit-> undo & textEdit->redo
in Qt4 I can find out if they are enabled, but not how to use them.
I would appreciate some help
thanks
Re: simple questions. qt3 to qt4
Quote:
Qt3: text = listBox ->text ( index ); and/or item index from QListBox. how in QListView or QListWidget or ???
QListWidget
item(row)->text()
Quote:
in Qt4 I can find out if they are enabled, but not how to use them.
Look at editing key bindings in QTextEdit class Reference.
Re: simple questions. qt3 to qt4
Quote:
Originally Posted by munna
QListWidget
item(row)->text()
Look at editing key bindings in QTextEdit class Reference.
Thanks, but, if I understand your suggestion corectly, key bindings are not what I'm looking for.
I am writing a program, not using one.
my question is "How do I put, in my program, the functionality of textedit's "undo" & "redo" present in Qt3?
Re: simple questions. qt3 to qt4
I have solved my list box problem by using QListWidget, but the "undo" and "redo" remain.
Re: simple questions. qt3 to qt4
Quote:
Originally Posted by impeteperry
"undo" and "redo" remain
This should make your life easier..
Code:
textEdit->setUndoRedoEnabled(true);
actionUndo->setEnabled(false);
actionRedo->setEnabled(false);
connect(actionUndo, SIGNAL(triggered()), textEdit->document(), SLOT(undo()));
connect(actionRedo, SIGNAL(triggered()), textEdit->document(), SLOT(redo()));
connect(textEdit, SIGNAL(undoAvailable(bool)), actionUndo, SLOT(setEnabled(bool)));
connect(textEdit, SIGNAL(redoAvailable(bool)), actionRedo, SLOT(setEnabled(bool)));
See also Editing key bindings.
Re: simple questions. qt3 to qt4
Thanks, What it looks like is that they have dropped the "undo" & "redo" functions entirely in Qt4, and what you suggest is a "work around". I can do that, but I'm not happy.
Thanks for your help. I really needed that.
Re: simple questions. qt3 to qt4
Quote:
Originally Posted by impeteperry
What it looks like is that they have dropped the "undo" & "redo" functions entirely in Qt4, and what you suggest is a "work around". I can do that, but I'm not happy.
It's not a "workaround". The new QTextEdit (and QTextBrowser) is based on the underlying document. QTextDocument is a new class in Qt 4 and represents the structure of a rich text document. The document is now responsible for undo/redo functionality. What are you not happy with? Too complicated? :p
Re: simple questions. qt3 to qt4
Your comment is funny and kind of hits the mark.
In all the programming I have done since the '70s (self taught) that which I didn't understand seemed complicated.
For some reason this switch from Qt3 to Qt4 has been dificult for me.
Looking at the QTextEdit documentation, I did not see a reference to QTextDocument, so I did not find the "undo" function which I knew had to be somewhere. I did a search for "undo" on the whole QTextEdit class document, came up with the "isUndoEnabled"s but no plain "undo."
Thanks to you, I'm now happy.
Re: simple questions. qt3 to qt4
i should say "almost" happy.
Thanks to your help and the "textEdit" demo, I now have a QTextEdit where I can edit, undo & redo BUT I need to convert the QTextStream to a QString. i see that there is a "QTextStream::readAll ();" member to do that, But I am having trouble codeing it.
Among many uses,i have a large number of small strings (people's addreses" which I keep in a "StringList" for easy handling.
Some more help would be appreciated.
PS. What I don't understand; I use a "QTextEdit" widget to edit some text.
"now is the tim for all good men\nto come to the aid.....", I miss-spelled "time" so I go to the widget that is designed to "edit text", or so it's name implies, and add the "e" to "tim". And I should now have a "now is the time for all good men\nto come to the aid....." bit of text, but no, I now have a QTextStream what ever that is. There is enough functionality in QString for me to implement my own "undo/redo" and most of the other stuff that they have put in "TextEdit" as shown in the demo. It looks like "Microsolt" wrote it to me.
There, now if I could get my text out of "textEdit" I would really be happy.
Please excuse the blow off.
Re: simple questions. qt3 to qt4
I find << and >> operators convenient.
You don't "convert" a stream to a string, you read from a stream to a string.
Following example demonstrates usage of QTextStream and QStringList:
Code:
// writing strings to a stream
textStream << string1 << " " << string2;
// stream's internal data
qDebug() << data; // outputs "string 1 string 2"
// reading from a stream to a string list
while (!textStream.atEnd())
{
textStream >> word;
wordList << word;
}
qDebug() << wordList; // outputs ("string", "1", "string", "2")
// writing a string list to a stream
textStream << word;
qDebug() << textStream.readAll(); // outputs "string1string2"
Hope you find it useful! And if not, please give a bit more comprehensive explanation of what you are trying to do..
Re: simple questions. qt3 to qt4
while I'm digesting your reply. let me give youa run down on what I'n doing.
1. I am an engineer and am writing programs for specific applications for non-computer savy users.
2. I do not use "pop-up" or "tool bars" in the usual sense.
3. I use a "control" string for program control.
" a,b,c,d,e,f, etc." where each position will have progam information. For example "e" might be "123-4x16" representing the location of column "d" on level "b" etc. With this system any module or function knows what it is dealing with by accessing this control string.
4 I use a "functionNumber" for program flow.
5 I have a "masterList" QStringList where each element in the list is itself a QStringList which can be split into ies own string list, names of buttons, prompts etc. each element in these sub-lists are keyed to the functionNumber.
It is this masterlist I need to be able to edit. I Join the elements into one long string and put it in a "textEdit" widget for editing.
6. Program operation is totally language ( and/or spelling ) independent. With the "signal-slot" system, programming is a breeze.
7. I have a row of Pushbuttons accross the bottom of the screen and a row of labels obove them representing the keyboard function keys for implementing a given function. The labels on the pushbuttons name the function. The names come from the appropiate sub-list of the master list mentioned above.
8. The user has his/her choice of pushing a function key, entering an accelerator key (given in the label on the push button) ,clicking on a pushbutton with the mouse or dbl clicking on an option when there is one.
The key to the whole system is the masterList. I have a single textEdit Wiget with the MasterList broken down in to a single string text. Qt3 was great for this.
If I know how to attach a snapshot I would or if you send me an e-mail at "impeteperry@cox.net" I can send you some.
Re: simple questions. qt3 to qt4
Thanks, please forget all that has gone before, QTextStreams, QTextEdit widgets, Undos, redos, my rantings and ravings etc.
All I need is the code to put in my program for a user to be able to change the word "sunny" to "raining" in the QString k. "It is sunny today".
In Qt3 where "myTextEdit" is an instance of the QTextEdit widget.
"myTextEdit->setText( k );"
"k = myTextEdit->text();".
Please, what is the code to do that in Qt4? (Text in, text out.)
Re: simple questions. qt3 to qt4
Quote:
Originally Posted by impeteperry
All I need is the code to put in my program for a user to be able to change the word "sunny" to "raining" in the QString k. "It is sunny today".
QString::replace()
Re: simple questions. qt3 to qt4
I feel like an idiot. What I have been looking for from the beginning is:
QString QTextEdit::toPlainText () const
This line of code solves all my problems. I don't know how I missed it.
I thank you for your efforts, they are very much appreciated.
pete perry.
Re: simple questions. qt3 to qt4
Ahh, I didn't realize that the issue was about retrieving the contents of the text edit.. :)
Re: simple questions. qt3 to qt4
Quote:
Originally Posted by jpn
Ahh, I didn't realize that the issue was about retrieving the contents of the text edit.. :)
Ain't communication fun!
I'm going to the Linux World conference in Boston tomorrow. Do you ever get to the US?. I've been to Denmark & Sweden, but not Finland. Again Thanks.
Re: simple questions. qt3 to qt4
Quote:
Originally Posted by impeteperry
Ain't communication fun!
I'm going to the Linux World conference in Boston tomorrow. Do you ever get to the US?. I've been to Denmark & Sweden, but not Finland. Again Thanks.
Not that I have plans or anything, but who knows, maybe some day.. No problem at all. :)