[Qt-interest] Display QWidget in foreground without taking focus and events

Bertrand ROOS bertrand.roos at wimo.fr
Mon Apr 18 12:15:25 CEST 2011


Thanks Zeljko for your answer.
Now the QTextBrowser takes focus (eg i see a blinking cursor when a click on it), but i cannot move the cursor by clicking or select text.

Nevertheless all events (including mouse events) should be stopped by writing following code, but it doesn't work:

void Picture::event(QEvent * e)
{
      if(e->type() == QEvent::Paint)
       {
          return true;
       }
      else
      {
           return false;
       }
}

Bertrand



Le 15/04/2011 10:35, Zeljko a écrit :
> Bertrand ROOS wrote:
>
>> Hi all,
>>
>> I'am trying to display a QWidget in foreground of a parent QWidget,
>> without taking focus and events.
>> I take an example to explain :
>> I have a QTextBrowser where I want to display a transparent picture in
>> foreground, but I want the user to be able to select text behind.
>>
>> I tried to overload the event fonction of the picture (a QWidget) to
>> return false, and then all event will be processed by the QTextBrowser.
>> I show you a minimal code source example :
>> void Picture::event(QEvent * e)
>> {
>>       if(e->type() == QEvent::Paint)
>>       {
>>           return true;
>>       }
>>       else
>>       {
>>           return false;
>>       }
>> }
>>
>>
>> I also tried to use an event filter to redirect event to the
>> QTextbrowser by using a eventFilter using the following code :
>> TextBrowser::TextBrowser(QWidget * parent) : QTextBrowser(parent)
>> {
>>       Picture = new MyPicture(this);
>>
>>       QGridLayout* layout = new QGridLayout(this);
>>       layout->addWidget(Picture,0,0,1,1);
>>       setLayout(layout);
>>
>>       Logo->installEventFilter(this);
>>       Logo->setFocusProxy(this);
>> }
>>
>> bool TextBrowser::eventFilter(QObject *obj, QEvent *event)
>> {
>>       if (obj == Picture)
>>       {
>>           if (event->type() == QEvent::Paint)
>>           {
>>               return false;
>>           }
>>           else
>>           {
>>               return QTextBrowser::eventFilter(obj, event);
>>           }
>>       }
>>       else
>>       {
>>           return QTextBrowser::eventFilter(obj, event);
>>       }
>> }
>>
>> I don't know if it is my implementation that is wrong, or if I must use
>> another function which will fit better.
>> If someone could give me an advice, I would be pleased.
> Set needed attributes (FocusOnActivate or similar) over your widget and focus
> policy (Qt::NoFocus). Then it shouldn't take focus in any case, but can react on
> mouse events (eg click ), so you must stop that events only.
>
> zeljko
>
>> Best regards.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list