It's a matter of passing the QTextEdit widget a proper parent.
It's a matter of passing the QTextEdit widget a proper parent.
J-P Nurmi
Thanks, it came to me last night what I was doing wrong.
I am still having problems which I have narrowed down to maybe a Qt problem.
I want to "show" a "help" box on a "QPainter" drawinq. I want to "toggle" this "box" by means of the keyboard "F1" key.
Line #4 in the following code activates a HelpFunction class to do this as has been suggested and line #5 does this in the painter function itself.
The first thumbnail just shows the drawing. The second shows the HelpFunction class "help box" after pressing the "F1" key.. The third shows the "help box" when generate by the painter itself.
The code below is for the HelpFunction class. Below the horizontal line controls the toggle function.Qt Code:
///----------------------------------------------------------------------------Pb1 void BaseForm::slotPb1() { emit activate(); paintList.append("help"); emit displayErectionDrawing(paintList, helpFlag); }To copy to clipboard, switch view to plain text mode
Line 23 displays the status of the toggle so I can tell if the "F1" keystroke was received.
There are several problemsQt Code:
{ frameH->setAutoFillBackground ( true ); teHBox->setAutoFillBackground(true); teHBox->setReadOnly ( true ); } void HelpFunction::slotActivate() { emit getDrawingFrameSize ( &W, &H ); emit getTextListItem(2, &k); frameH->setGeometry ( W - 350, H - 420, 350, 430 ); teHBox->setGeometry ( 10, 10, 330, 410 ); teHBox->setPlainText ( k ); emit showHelpFrame(frameH); //-------------------------------------------------------------------------- if(helpFlag == false) k = "false"; else k = "true"; emit setMessageBox("help 15 helpFlag = " + k); if(helpFlag == true) helpFlag = false; else if(helpFlag == false) helpFlag = true; else helpFlag = true; }To copy to clipboard, switch view to plain text mode
1. the first time the "F1" key was pressed, the HelpFunction "help box" was displayed as shown in the second thumbnail.
2. After that, pressing the "F1" key had no effect.
3. Clicking anywhere on the screen with the left mouse button closed the HelpFunction "help box" and left the "painter" help box displayed.
4. Now the "F1" key toggled the "painter" help box.
5, If I changed line #3 of the HelpFunction class to "frameH = new QFrame(this);", the toggle worked fine for the "painter" box thumbnail #2.
6. CONCLUSION: When the "Help Function" box was displayed, the "F1" key was DEACTIVATED.
If we get problem #6 corrected, I would much prefer the "Box" to look like the "painter" box, but with scroll bars and the functionality of the QTextEdit widget.
If I am doing somthing wrong, I am including the pb1 and fk1clicked items which have worked flawlessly up to now.
[/CODE]Qt Code:
connect ( Pb1, SIGNAL ( clicked() ), this, SLOT ( slotPb1() ) ); ///--------------------------------------------------------Function Keys connect ( this, SIGNAL ( fk1clicked() ), this, SLOT ( slotPb1() ) );To copy to clipboard, switch view to plain text modeThank you very muchQt Code:
{ int n; QString h; n = k->key(); h = h.setNum ( n ); if ( k->key() == 16777264 && Pb1->text() != "-" ) emit fk1clicked(); if ( k->key() == 16777265 && Pb2->text() != "-" ) emit fk2clicked();To copy to clipboard, switch view to plain text mode
Ok, I don't blame you all if you are fed up with me, but please give me a answer
Can I do what I want to in Qt4?
Thanks
You see... the problem is we are not seeing your problemI suggest you forget about F keys and all that stuff and focus on implementing a widget with properties that allow you to modify the behaviour of the widget. When you have that done, start thinking about function keys.
Thanks for your suggestion, but I'm afraid you are missing the point of my program.
I am an engineer and innovator in the building industry. I have had 2 growing problems with the computer industry over the past 35 years. The complexity of the user interface (look at Blender) and the CAD programs in principle
This may not be the proper forum for a discussion of this type. Please let me know if it is oK or suggest another Qt forum .
Thasks
pete perry
I'm not. You're missing the point of your problem. You have problems with drawing, not with input events. That's why I say to make your widget draw in a predictable, reproducable and desirable way and only then add value to it, not the other way round.
Please don't insult us. You know nothing of us or problems we are dealing with. At the same time you are asking for help with your problem, not the other way round.I am an engineer and innovator in the building industry. I have had 2 growing problems with the computer industry over the past 35 years. The complexity of the user interface (look at Blender) and the CAD programs in principle
This may not be the proper forum for a discussion of this type. Please let me know if it is oK or suggest another Qt forum .
As for one of your questions - switching to Qt4 is a good idea in general, especially that it will probably force or encourage you to do it the right way - using QGraphicsView and not drawing directly inside a frame. You should have used QCanvas...
Your code cries: refactor me! But what do I know.... I'm not dealing with problems complex enough to know anything about yours...
impeteperry (31st March 2008)
Sir, I am not insulting you, Qt or anybody else. I appreciate your effort to help me. so enough of that!
I thought the forum was for help on my problems using your product rather then the other way around.
The use of the "function/accelerator keys" for program control rather then the mouse is part and parcel of what I am trying to develop, right or wrong.
My problem is "I can show a "Help widget" on a painter by pressing a function key, but I can't delete it by pressing a function key". My Question is "what code to I need to add to my "help Widget to correct this problem"?
I see that Qt 4 no longer lists QCanvas, however I shall go back to square one, look at QGraphicView and see if I an do in Qt what I did in DOS.
Again, I am sorry if I offended you in any way, sometimes I don't express myself to well.
Thanks
I went to "examples" for QGraphicview and found collindingmice. Oh what a delightful examole!!!
I see there is layering there. Let you know how I make out.
Thanks again,
Last edited by impeteperry; 31st March 2008 at 21:25.
But that's not the issue here. If you have other things working, adding accelerators is trivial. If something doesn't work, it means the problem is elsewhere.
You need to implement a paint event correctly, so that it takes into consideration the help widget. I'd add a property holding the help text to show and when the text is empty, hide the help and otherwise render the text. Something like:My problem is "I can show a "Help widget" on a painter by pressing a function key, but I can't delete it by pressing a function key". My Question is "what code to I need to add to my "help Widget to correct this problem"?
Qt Code:
class MyClass: public ... { Q_OBJECT public: //... public slots: if(txt==m_helpText) return; m_helpText = txt; update(); } protected: void paintEvent(...){ //... if(!m_helpText.isEmpty()){ p.save(); //... p.drawRect(...); p.drawText(...); p.restore(); } } };To copy to clipboard, switch view to plain text mode
Actually I'd use QCanvas or QGraphicsView...
Taking your advice, I am looking at QGraphicView-scene. As I said, I would start from scratch. This looks promising.
Being a bit mentally retarded at 82 and in need of an eye operation it will take a bit of time.
I am a little leery of QCanvas as it is no longer listed in the Qt documentation under "all classes". (I did some stuff with it under Qt 3).
QCanvas and QGraphicsView are very similar. There's even an article written by Andreas on QQ on porting QCanvas applications to Graphics View.
I'm confused. If QCanvas is not listed Qt4, do you mean go back to Qt3 or that If I worked in QCanvas in Qt3, I should not have any problem with QGraphicsview in Qt 4?
Bookmarks