August 8, 2011

yan bellavance yan bellavance
Lab Rat
66 posts

[SOLVED] focus problem on Ubuntu when using QMessageBoxes

 

It looks like there is a bug when running Qt apps on Ubuntu, I don’t know if the bug is on the Qt side or the Ubuntu but I have a feeling that this was not present in past versions of Ubuntu and I do not see this happen on red hat. Im hoping you guys can validate if I am doing something wrong first.

Here is the situation: I push a button on my ui which is connected to a slot. Inside that slot I open a QMessageBox. If i click on the Ok button everything is fine but if i simply click enter without focusing on the message box first the I cannot edit QLineEdits or QSpinBoxes of that ui until i focus another window then come back to it. Here is the slot’s code in my QMainWindow:

  1.     void on_pushButton_clicked(){
  2.        
  3.         QMessageBox clrMsg;
  4.         clrMsg.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
  5.         clrMsg.setWindowTitle("IRIG-B");
  6.         clrMsg.setText("Are you sure you want to clear the IRIG-B faults?");
  7.         int res=clrMsg.exec();
  8.         if(res==QMessageBox::Yes){
  9.             //...do my stuff
  10.         }
  11.     }

P.S. I am currently using ubuntu 10.04 LTS. This is easilly reproducable, just add this slot to the MainWindow of a new project and add a pushbutton, qlineedit and qspinbox to the mainwindow form. Start the app, click the pushbutton, click enter , try to edit spinboxes or lineedits->res: can’t edit them with keyboard unless you alt+tab and back first

3 replies

August 9, 2011

alexisdm alexisdm
Ant Farmer
128 posts

Does it do the same thing if you add the main window (this) as parent of the message box ?

August 9, 2011

yan bellavance yan bellavance
Lab Rat
66 posts

that’s a good point. let me try that.

August 9, 2011

yan bellavance yan bellavance
Lab Rat
66 posts
alexisdm wrote:
Does it do the same thing if you add the main window (this) as parent of the message box ?

It worked thanks! I am curious to know why this was not necessary on red hat and also on another ubuntu (10.04 LTS 32 bit vmware using qt4.7 instead of qt4.6)

 
  ‹‹ [Moved] Filter an image with an qRGB component.      [SOLVED] Have text in QLineEdit selected on edit start ››

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