August 21, 2012

haney haney
Lab Rat
25 posts

QTextEdit Ctrl + + zoomIn keyevent not working in Windows

 

Hi,

I developed an editor using QTextEdit. In this zoomIn option is working for Ctrl + ‘+’. But when I press Ctrl + Shift + ‘=’ keys zoomIn feature is not working.

In linux by default, Ctrl +Shift +’=’ is working. In windows it is not working.

Ctrl+Shift+= is same as Ctrl ++

I tried to capture the events in keypressEvent(QKeyEvent *e) method like this:

  1.  if(e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Plus)
  2.     {
  3.             this->zoomIn();
  4.             qDebug()<<"key ctrl shift + pressed";
  5.     } // not working
  6.  
  7. // second trial
  8. if(e->modifiers() == Qt::ControlModifier &&e->modifiers() == Qt::ShiftModifier && e->key() == Qt::Key_Equal)
  9. {
  10.             this->zoomIn();
  11.             qDebug()<<"key ctrl shift + pressed";
  12. } // not working

How can I make Ctrl+shift+’=’ make zoomIn in textEdit. How can I capture these keypresses combination.

Please suggest your views on this.

Appreciate your help in this regard.

Thanks,
Haney.

}

2 replies

August 21, 2012

haney haney
Lab Rat
25 posts

I tried even the nativeScanCode() each key has a unique scan code. I cannot differentiate = and + using scan code cuz it is one key, hence same scancode.

How to catch the combination of key press like Ctrl + Shift + ‘=’ .

Please give any suggestions.

August 22, 2012

haney haney
Lab Rat
25 posts

I was able to do it this way.

  1. Qt::KeyboardModifiers mod = QApplication::keyboardModifiers ();
  2.             bool SHIFT = mod.testFlag(Qt::ShiftModifier);
  3.             bool CTRL = mod.testFlag(Qt::ControlModifier);
  4.  
  5.             if (SHIFT && CTRL)
  6.             {
  7.                 if(e->key() == Qt::Key_Plus){
  8.  
  9.                     qDebug()<<"now plus caught";
  10.                     this->zoomIn();
  11.              }

 
  ‹‹ insert table      Qt3D / plugin "mouse3d" ››

You must log in to post a reply. Not a member yet? Register here!