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.
///----------------------------------------------------------------------------Pb1
void BaseForm::slotPb1()
{
emit activate();
paintList.append("help");
emit displayErectionDrawing(paintList, helpFlag);
}
///----------------------------------------------------------------------------Pb1
void BaseForm::slotPb1()
{
emit activate();
paintList.append("help");
emit displayErectionDrawing(paintList, helpFlag);
}
To copy to clipboard, switch view to plain text mode
The code below is for the HelpFunction class. Below the horizontal line controls the toggle function.
Line 23 displays the status of the toggle so I can tell if the "F1" keystroke was received.
{
frameH->setAutoFillBackground ( true );
frameH
->setFrameShape
( QFrame::Box );
frameH
->setPalette
( QColor ( 200,
200,
200 ) );
teHBox->setAutoFillBackground(true);
teHBox
->setPalette
(QColor ( 210,
255,
255 ));
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;
}
HelpFunction::HelpFunction(QWidget *parent) : QWidget(parent)
{
frameH = new QFrame();
frameH->setAutoFillBackground ( true );
frameH->setFrameShape ( QFrame::Box );
frameH->setPalette ( QColor ( 200, 200, 200 ) );
teHBox = new QTextEdit ( frameH );
teHBox->setAutoFillBackground(true);
teHBox->setPalette(QColor ( 210, 255, 255 ));
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
There are several problems
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.
connect ( Pb1, SIGNAL ( clicked() ), this, SLOT ( slotPb1() ) );
///--------------------------------------------------------Function Keys
connect ( this, SIGNAL ( fk1clicked() ), this, SLOT ( slotPb1() ) );
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 mode
[/CODE]
void BaseForm
::keyPressEvent ( QKeyEvent *k
) {
int n;
n = k->key();
h = h.setNum ( n );
if ( k->key() == 16777264 && Pb1->text() != "-" ) emit fk1clicked();
if ( k->key() == 16777265 && Pb2->text() != "-" ) emit fk2clicked();
void BaseForm::keyPressEvent ( QKeyEvent *k )
{
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
Thank you very much
Bookmarks