Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, May 2007
How to prevent QWidget::move()?


Message 1 in thread

I need to prevent certain windows in my QWorkspace from moving and/or
changing size. Preventing a size change is easy (setFixedSize()), but I
cannot find any way to prevent a QWidget from being relocated. I looked
through both QWidget and QWorkspace (since the workspace is always the
parent in this case) and couldn't find any methods or flags that make a
QWidget unmovable. (Did I miss something?)

I thought about overriding the MoveEvent, but the object is already
relocated when this is called, and moving it back would cause recursion (not
to mention being extremely ugly).

Does anyone have an answer to this? How do I prevent the user from moving
specified widgets in a workspace?

Using Qt 4.2.3.

Keith
**Please do not reply to me, reply to the list.**


Message 2 in thread

I should have said I need to prevent the user from moving the window. I can
prevent myself from moving it programmatically.

It would be nice to do this for QDialogs as well.

Keith
**Please do not reply to me, reply to the list.**

On 05-18-2007 11:32 AM, "Keith Esau" wrote:

> I need to prevent certain windows in my QWorkspace from moving and/or changing
> size. Preventing a size change is easy (setFixedSize()), but I cannot find any
> way to prevent a QWidget from being relocated. I looked through both QWidget
> and QWorkspace (since the workspace is always the parent in this case) and
> couldn't find any methods or flags that make a QWidget unmovable. (Did I miss
> something?)
> 
> I thought about overriding the MoveEvent, but the object is already relocated
> when this is called, and moving it back would cause recursion (not to mention
> being extremely ugly).
> 
> Does anyone have an answer to this? How do I prevent the user from moving
> specified widgets in a workspace?
> 
> Using Qt 4.2.3.
> 
> Keith
> **Please do not reply to me, reply to the list.**


Message 3 in thread

We have a similar issue with our product since it acts as a medical 
device.   We solve this in 2 ways (1) don't run the window manager (and 
since we deliver the whole system, that's easy), and (2) we set 
Qt::FramelessWindowHint on the top level window for which all dialogs, 
etc are children.  You could set that flag on any dialog/window you 
want.  What you must do then is position the dialog/window 
programatically.  The user is prevented from moving or resizing because 
there is no window manager frame.

HTH,
Susan

Keith Esau wrote:
> I should have said I need to prevent the *_user_* from moving the 
> window. I can prevent myself from moving it programmatically.
>
> It would be nice to do this for QDialogs as well.
>
> Keith
> **Please do not reply to me, reply to the list.**
>
> On 05-18-2007 11:32 AM, "Keith Esau" wrote:
>
>     I need to prevent certain windows in my QWorkspace from moving
>     and/or changing size. Preventing a size change is easy
>     (setFixedSize()), but I cannot find any way to prevent a QWidget
>     from being relocated. I looked through both QWidget and QWorkspace
>     (since the workspace is always the parent in this case) and
>     couldn't find any methods or flags that make a QWidget unmovable.
>     (Did I miss something?)
>
>     I thought about overriding the MoveEvent, but the object is
>     already relocated when this is called, and moving it back would
>     cause recursion (not to mention being extremely ugly).
>
>     Does anyone have an answer to this? How do I prevent the user from
>     moving specified widgets in a workspace?
>
>     Using Qt 4.2.3.
>
>     Keith
>     **Please do not reply to me, reply to the list.**
>



---

This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.


Message 4 in thread

Good idea, unfortunately I need the window frames. Unmovable is just an
attribute to our windows. They look like normal windows in every other
respect.

Yeah, I know it's bad UI, but legacy support is legacy support even if it is
a bad idea.

Keith
**Please do not reply to me, reply to the list.**


On 05-18-2007 12:22 PM, "Susan Macchia" wrote:

> We have a similar issue with our product since it acts as a medical device.
> We solve this in 2 ways (1) don't run the window manager (and since we deliver
> the whole system, that's easy), and (2) we set Qt::FramelessWindowHint on the
> top level window for which all dialogs, etc are children.  You could set that
> flag on any dialog/window you want.  What you must do then is position the
> dialog/window programatically.  The user is prevented from moving or resizing
> because there is no window manager frame.
> 
> HTH,
> Susan
> 
> Keith Esau wrote:
>>  Re: How to prevent QWidget::move()? I should have said I need to prevent the
>> user from moving the window. I can prevent myself from moving it
>> programmatically.
>>  
>> It would be nice to do this for QDialogs as well.
>>  
>> Keith
>>  **Please do not reply to me, reply to the list.**
>>  
>> On 05-18-2007 11:32 AM, "Keith Esau" wrote:
>>  
>>   
>>> I need to prevent certain windows in my QWorkspace from moving and/or
>>> changing size. Preventing a size change is easy (setFixedSize()), but I
>>> cannot find any way to prevent a QWidget from being relocated. I looked
>>> through both QWidget and QWorkspace (since the workspace is always the
>>> parent in this case) and couldn't find any methods or flags that make a
>>> QWidget unmovable. (Did I miss something?)
>>>  
>>> I thought about overriding the MoveEvent, but the object is already
>>> relocated when this is called, and moving it back would cause recursion (not
>>> to mention being extremely ugly).
>>>  
>>> Does anyone have an answer to this? How do I prevent the user from moving
>>> specified widgets in a workspace?
>>>  
>>> Using Qt 4.2.3.
>>>  
>>> Keith
>>>  **Please do not reply to me, reply to the list.**
>>>  


Message 5 in thread

There must be some hint that you can give the window to turn "move" off 
for the window - I'd google & search the TT docs.

<keith.esau@xxxxxxx>Keith Esau wrote:
> Good idea, unfortunately I need the window frames. Unmovable is just 
> an attribute to our windows. They look like normal windows in every 
> other respect.
>
> Yeah, I know it's bad UI, but legacy support is legacy support even if 
> it is a bad idea.
>
> Keith
> **Please do not reply to me, reply to the list.**
>
>
> On 05-18-2007 12:22 PM, "Susan Macchia" wrote:
>
>     We have a similar issue with our product since it acts as a
>     medical device.   We solve this in 2 ways (1) don't run the window
>     manager (and since we deliver the whole system, that's easy), and
>     (2) we set Qt::FramelessWindowHint on the top level window for
>     which all dialogs, etc are children.  You could set that flag on
>     any dialog/window you want.  What you must do then is position the
>     dialog/window programatically.  The user is prevented from moving
>     or resizing because there is no window manager frame.
>
>     HTH,
>     Susan
>
>     Keith Esau wrote:
>
>         Re: How to prevent QWidget::move()? I should have said I need
>         to prevent the *_user_* from moving the window. I can prevent
>         myself from moving it programmatically.
>          
>         It would be nice to do this for QDialogs as well.
>          
>         Keith
>          **Please do not reply to me, reply to the list.**
>          
>         On 05-18-2007 11:32 AM, "Keith Esau" wrote:
>          
>           
>
>             I need to prevent certain windows in my QWorkspace from
>             moving and/or changing size. Preventing a size change is
>             easy (setFixedSize()), but I cannot find any way to
>             prevent a QWidget from being relocated. I looked through
>             both QWidget and QWorkspace (since the workspace is always
>             the parent in this case) and couldn't find any methods or
>             flags that make a QWidget unmovable. (Did I miss something?)
>              
>             I thought about overriding the MoveEvent, but the object
>             is already relocated when this is called, and moving it
>             back would cause recursion (not to mention being extremely
>             ugly).
>              
>             Does anyone have an answer to this? How do I prevent the
>             user from moving specified widgets in a workspace?
>              
>             Using Qt 4.2.3.
>              
>             Keith
>              **Please do not reply to me, reply to the list.**
>



---

This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.


Message 6 in thread

Gi,

> There must be some hint that you can give the window to turn "move" off 
> for the window - I'd google & search the TT docs.

On which platform is this by the way. It may not be possible on X11 for example.

--
 [ signature omitted ] 

Message 7 in thread

Generally speaking, on X11 you can certainly set window manager hints to 
turn off various WM functions.  I've done it (in a past life ;)) under 
Motif/Xt.  The question is whether there is a Qt interface to do this 
(there should be if there isn't).  It may even be at the Xlib level, I 
just don't remember exactly.

Dimitri wrote:
> Gi,
>
>> There must be some hint that you can give the window to turn "move" 
>> off for the window - I'd google & search the TT docs.
>
> On which platform is this by the way. It may not be possible on X11 
> for example.
>
> -- 
> Dimitri
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>



---

This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.

--
 [ signature omitted ] 

Message 8 in thread

I am referring primarily to widgets within the workspace. Platform should
not matter. The QMainWindow is free to move.


On 05-18-2007 12:40 PM, "Dimitri" wrote:

> Gi,
> 
>> There must be some hint that you can give the window to turn "move" off
>> for the window - I'd google & search the TT docs.
> 
> On which platform is this by the way. It may not be possible on X11 for
> example.
> 
> --
> Dimitri


--
 [ signature omitted ] 

Message 9 in thread

BTW, I do not want to do platform specific things. Our application is
intended to run on at least 4 platforms (Windows, Linux, HPUX, and Solaris)
and possibly a 5th (Mac). The solution needs to work everywhere that it is
reasonable.

I already had to write kludge code once to trap an "interrupt" key before it
got in the message queue, but this is not nearly as low-level as that was.

Since moving widgets in a workspace has to be maintained by Qt anyway, there
should be some way to prevent it. Can I trap the mousePressEvent in the
title bar?


On 05-18-2007 1:21 PM, "Keith Esau" wrote:


> I am referring primarily to widgets within the workspace. Platform should
> not matter. The QMainWindow is free to move.
> 
> 
> On 05-18-2007 12:40 PM, "Dimitri" wrote:
> 
>> Gi,
>> 
>>> There must be some hint that you can give the window to turn "move" off
>>> for the window - I'd google & search the TT docs.
>> 
>> On which platform is this by the way. It may not be possible on X11 for
>> example.
>> 
>> --
>> Dimitri


--
 [ signature omitted ] 

Message 10 in thread

Anyone tell me what I'm doing wrong here? There is no compile time error 
with
the following code, but the result in s is garbage in Qt 4.3.0rc1. In Qt 
3.x this
worked fine.

  QLineEdit *source = new QLineEdit(this);
  source->setText(QString("test!"));
  const char *s = source->text().toAscii();

Replacing the last line with:

  const char *s = source->text().toAscii().data();

also results in garbage.

- Keith

--
 [ signature omitted ] 

Message 11 in thread

On 19.05.07 11:09:48, Keith Sabine wrote:
> Anyone tell me what I'm doing wrong here? There is no compile time error with
> the following code, but the result in s is garbage in Qt 4.3.0rc1. In Qt 3.x 
> this
> worked fine.
> 
>  QLineEdit *source = new QLineEdit(this);
>  source->setText(QString("test!"));
>  const char *s = source->text().toAscii();

That returns a QByteArray, as can be seen in the documentation and a
QByteArray is not equal to char*.

> Replacing the last line with:
> 
>  const char *s = source->text().toAscii().data();
> 
> also results in garbage.

The QByteArray that is returned from toAscii() is a temporary which
goes out of scope right after the semicolon on the line. And with it it
takes its char* internal data buffer. So you need to either copy it via
str* (can't recall the exact name) or you need to make sure the
QByteArray lives longer, by creating a local variable for it:

QByteArray ar = source->test().toAscii();
s = ar.data();
dosoemthing(s);

Andreas

-- 
 [ signature omitted ] 

Message 12 in thread

Andreas Pakulat wrote:
> The QByteArray that is returned from toAscii() is a temporary which
> goes out of scope right after the semicolon on the line. And with it it
> takes its char* internal data buffer. So you need to either copy it via
> str* (can't recall the exact name) or you need to make sure the
> QByteArray lives longer, by creating a local variable for it:
>
>   
Thanks Andreas, pity there is no compiler warning though as searching 
through
the code for all the possible occurrences is not easy!

- Keith

--
 [ signature omitted ] 

Message 13 in thread

On 19.05.07 12:22:40, Keith Sabine wrote:
> Andreas Pakulat wrote:
> >The QByteArray that is returned from toAscii() is a temporary which
> >goes out of scope right after the semicolon on the line. And with it it
> >takes its char* internal data buffer. So you need to either copy it via
> >str* (can't recall the exact name) or you need to make sure the
> >QByteArray lives longer, by creating a local variable for it:
> >  
> Thanks Andreas, pity there is no compiler warning though as searching through
> the code for all the possible occurrences is not easy!

This is not detectable by the compiler, also a grep -r "toAscii" *
should give you the occurrences.

Andreas

-- 
 [ signature omitted ] 

Message 14 in thread

On 5/18/07, Keith Esau <keith.esau@xxxxxxx> wrote:
>
>  Good idea, unfortunately I need the window frames. Unmovable is just an
> attribute to our windows. They look like normal windows in every other
> respect.
>
>  Yeah, I know it's bad UI, but legacy support is legacy support even if it
> is a bad idea.

I do this on Windows by using QWidget::winEvent() to handle the
WM_ENTERSIZEMOVE message. The MSDN documentation explains how to
handle the message to prevent movement, or apply limits (preventing a
window from moving off-screen, etc.)

http://msdn2.microsoft.com/en-us/library/ms632622.aspx

-- 
 [ signature omitted ] 

Message 15 in thread

Well, I tried overriding the MoveEvent(), setting a flag and moving the
widget back to event->oldPos().

MoveEvent is never called!!!! (Big Qt bug there...) My widget is derived
directly from QWidget.

Keith
**Please do not reply to me, reply to the list.**


On 05-18-2007 11:32 AM, "Keith Esau" wrote:

> I thought about overriding the MoveEvent, but the object is already relocated
> when this is called, and moving it back would cause recursion (not to mention
> being extremely ugly).