Qt-interest Archive, July 2007
Moving a window before showing it
Message 1 in thread
I am going crazy trying to figure out how to bring a window up at a
specified location and size. QWidget::move() and QWidget::resize() simply do
not work before a window is shown and/or events are processed. I worked
around the resize problem by using setFixedSize, and then setting back the
maximum and minimum sizes, but I can't find an equivalent for moving the
window.
I am doing this with QMdiSubWindow widgets, but I had the same problem with
window widgets in QWorkspace. Does anyone know how to get a window to
display where I want it to?
Keith
**Please do not reply to me, reply to the list.**
Message 2 in thread
Keith Esau wrote:
> I am going crazy trying to figure out how to bring a window up at a
> specified location and size. QWidget::move() and QWidget::resize()
> simply do not work before a window is shown and/or events are
> processed. I worked around the resize problem by using setFixedSize,
> and then setting back the maximum and minimum sizes, but I can't find
> an equivalent for moving the window.
>
> I am doing this with QMdiSubWindow widgets, but I had the same problem
> with window widgets in QWorkspace. Does anyone know how to get a
> window to display where I want it to?
>
> Keith
> **Please do not reply to me, reply to the list.**
I had the similar problem before the widget is shown. My problem was
solved by this resize trick:
resize(1,1);
QSize size = sizeCalculate(); // bounding box
resize(size);
Best wishes,
Lingfa
--
[ signature omitted ]
Message 3 in thread
That won't work in my case, and like I said, I found a workaround for
resize. My big problem is placement of the window.
Keith
**Please do not reply to me, reply to the list.**
On 07-13-2007 1:35 PM, "Lingfa Yang" wrote:
> Keith Esau wrote:
>
>> I am going crazy trying to figure out how to bring a window up at a
>> specified location and size. QWidget::move() and QWidget::resize()
>> simply do not work before a window is shown and/or events are
>> processed. I worked around the resize problem by using setFixedSize,
>> and then setting back the maximum and minimum sizes, but I can't find
>> an equivalent for moving the window.
>>
>> I am doing this with QMdiSubWindow widgets, but I had the same problem
>> with window widgets in QWorkspace. Does anyone know how to get a
>> window to display where I want it to?
>>
>> Keith
>> **Please do not reply to me, reply to the list.**
>
>
> I had the similar problem before the widget is shown. My problem was
> solved by this resize trick:
>
> resize(1,1);
> QSize size = sizeCalculate(); // bounding box
> resize(size);
>
> Best wishes,
> Lingfa
--
[ signature omitted ]
Message 4 in thread
On Friday 13 July 2007 22:40, Keith Esau wrote:
> That won't work in my case, and like I said, I found a workaround for
> resize. My big problem is placement of the window.
I figured out, that since 4.3 move (x,y) is ignored if implemented in onShow
(...). It now only seems to work in show () and setVisible ().
So if you call move in the reimplemented show method, the widget should be
placed according to the given coordinates.
This is (from my testing) not valid for windows - there it works as before.
Frank
--
[ signature omitted ]
Message 5 in thread
Keith Esau schrieb:
> I am going crazy trying to figure out how to bring a window up at a
> specified location and size. QWidget::move() and QWidget::resize()
> simply do not work before a window is shown and/or events are processed.
Try reimplementing show() or exec(), whichever you use:
MyWindow::exec()
{
QDialog::show();
move(myPosition);
return QDialog::exec();
}
Not tested with MDI windows, so it may not be applicable. And this
workaround may cause other problems...
Martin
--
[ signature omitted ]
Message 6 in thread
Hi Keith,
> I am going crazy trying to figure out how to bring a window up at a
> specified location and size. QWidget::move() and QWidget::resize()
> simply do not work before a window is shown and/or events are processed.
> I worked around the resize problem by using setFixedSize, and then
> setting back the maximum and minimum sizes, but I can't find an
> equivalent for moving the window.
>
> I am doing this with QMdiSubWindow widgets, but I had the same problem
> with window widgets in QWorkspace. Does anyone know how to get a window
> to display where I want it to?
I don't see any problem with this here. Could you please show me how you
set the new geometry? Here's my example:
#include <QtGui>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QMdiArea mdiArea;
QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QWidget);
subWindow->setGeometry(100, 100, 200, 300);
// Or with resize() and move():
//subWindow->resize(200, 300);
//subWindow->move(100, 100);
mdiArea.show();
return app.exec();
}
--
[ signature omitted ]
Message 7 in thread
On 07-16-2007 1:22 AM, "Bjoern Erik Nilsen" wrote:
> Hi Keith,
>
>> I am going crazy trying to figure out how to bring a window up at a
>> specified location and size. QWidget::move() and QWidget::resize()
>> simply do not work before a window is shown and/or events are processed.
>> I worked around the resize problem by using setFixedSize, and then
>> setting back the maximum and minimum sizes, but I can't find an
>> equivalent for moving the window.
>>
>> I am doing this with QMdiSubWindow widgets, but I had the same problem
>> with window widgets in QWorkspace. Does anyone know how to get a window
>> to display where I want it to?
>
> I don't see any problem with this here. Could you please show me how you
> set the new geometry? Here's my example:
>
>
> #include <QtGui>
>
> int main(int argc, char **argv)
> {
> QApplication app(argc, argv);
>
> QMdiArea mdiArea;
> QMdiSubWindow *subWindow = mdiArea.addSubWindow(new QWidget);
> subWindow->setGeometry(100, 100, 200, 300);
> // Or with resize() and move():
> //subWindow->resize(200, 300);
> //subWindow->move(100, 100);
> mdiArea.show();
>
> return app.exec();
> }
This is what I was doing:
QRect fr = window->frameGeometry();
QRect gr = window->geometry();
gr.translate(newx - fr.left(), newy - fr.right());
window->setGeometry(gr);
Newx and newy are fairly large (>100), but the window constantly shows up at
4,25.
Keith
**Please do not reply to me, reply to the list.**
--
[ signature omitted ]
Message 8 in thread
I believe....
void QWidget::setGeometry ( int x, int y, int w, int h )
may be what you are looking for.
Benjamin Poiesz
bpoiesz1@xxxxxxx
On Jul 13, 2007, at 1:40 PM, Keith Esau wrote:
> That won't work in my case, and like I said, I found a workaround for
> resize. My big problem is placement of the window.
>
> Keith
> **Please do not reply to me, reply to the list.**
>
>
> On 07-13-2007 1:35 PM, "Lingfa Yang" wrote:
>
> > Keith Esau wrote:
> >
> >> I am going crazy trying to figure out how to bring a window up at a
> >> specified location and size. QWidget::move() and QWidget::resize()
> >> simply do not work before a window is shown and/or events are
> >> processed. I worked around the resize problem by using
> setFixedSize,
> >> and then setting back the maximum and minimum sizes, but I can't
> find
> >> an equivalent for moving the window.
> >>
> >> I am doing this with QMdiSubWindow widgets, but I had the same
> problem
> >> with window widgets in QWorkspace. Does anyone know how to get a
> >> window to display where I want it to?
> >>
> >> Keith
> >> **Please do not reply to me, reply to the list.**
> >
> >
> > I had the similar problem before the widget is shown. My problem was
> > solved by this resize trick:
> >
> > resize(1,1);
> > QSize size = sizeCalculate(); // bounding box
> > resize(size);
> >
> > Best wishes,
> > Lingfa
>
>
> --
> 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/
--
[ signature omitted ]
Message 9 in thread
Yeah, I believed that too, until I tried it. It doesn't work. I also tried
creating a QMoveEvent and using qapp->sendEvent() to the QMdiSubWindow. That
doesn't work either.
I did some more tracing, and the QMdiSubWindow::layout()->activate() call
(as part of the QMdiSubWindow::show()) overwrites the position that is saved
when calling doResize() (which despite the name sets the position as well).
I still haven't figured out how to prevent the move from being erased.
Keith
**Please do not reply to me, reply to the list.**
On 07-13-2007 3:47 PM, "Benjamin Poiesz" wrote:
> I believe....
>
> void QWidget::setGeometry ( int x, int y, int w, int h )
>
> may be what you are looking for.
>
> Benjamin Poiesz
> bpoiesz1@xxxxxxx
>
>
> On Jul 13, 2007, at 1:40 PM, Keith Esau wrote:
>
>> That won't work in my case, and like I said, I found a workaround for
>> resize. My big problem is placement of the window.
>>
>> Keith
>> **Please do not reply to me, reply to the list.**
>>
>>
>> On 07-13-2007 1:35 PM, "Lingfa Yang" wrote:
>>
>>> Keith Esau wrote:
>>>
>>>> I am going crazy trying to figure out how to bring a window up at a
>>>> specified location and size. QWidget::move() and QWidget::resize()
>>>> simply do not work before a window is shown and/or events are
>>>> processed. I worked around the resize problem by using
>> setFixedSize,
>>>> and then setting back the maximum and minimum sizes, but I can't
>> find
>>>> an equivalent for moving the window.
>>>>
>>>> I am doing this with QMdiSubWindow widgets, but I had the same
>> problem
>>>> with window widgets in QWorkspace. Does anyone know how to get a
>>>> window to display where I want it to?
>>>>
>>>> Keith
>>>> **Please do not reply to me, reply to the list.**
>>>
>>>
>>> I had the similar problem before the widget is shown. My problem was
>>> solved by this resize trick:
>>>
>>> resize(1,1);
>>> QSize size = sizeCalculate(); // bounding box
>>> resize(size);
>>>
>>> Best wishes,
>>> Lingfa
--
[ signature omitted ]
Message 10 in thread
Hi,
I have a very strange problem here.
I my constructor I create a QSqlQueryModel + a QTableView:
> _model = new QSqlQueryModel(this);
> _problemTable->setModel(_model);
When I add the query within the constructor, I always get an empty
table. The headers are set correctly for the query, but the table is
empty. When I try to get the data from the model as described in the
docs:
> QSqlQueryModel model;
> model.setQuery("SELECT * FROM employee");
> int salary = model.record(4).value("salary").toInt();
I can get my data correctly from the model. A qDebug() <<
_model->query().executedQuery() shows that the correct query is
executed, but the table is still blank.
Now I tried to set the query within a slot, which is activated by a
button click. Within this slot I only do:
> _model->setQuery("SELECT * FROM problemview2",
> QSqlDatabase::database("mydatabasename"));
The result is totally strange. The first time I press the button, an
empty row appears with the row number '1'. The grid is drawn, but all
cells are empty.
Now I press the button a second time and the data I expect appears, but
the empty row remains, e.g. when I expect three data records, I get
three + the empty row as last row. However, from the four rows only the
first one has a row number in column '0'.
When I finally press the button a third time all four lines are
numbered.
My bug? Trolltech's bug? My version is 4.3.0 on Linux.
Guido
--
[ signature omitted ]
Message 11 in thread
Hi!
>
> My bug? Trolltech's bug? My version is 4.3.0 on Linux.
I'm pretty sure, it is a bug in the library. I have similar results when
I use QSqlTableModel.
It works only flawlessly, if I operate ONLY on the model. If I operate
on the database directly (adding, removing rows) and use
QSqlTableModel::select() on this model, the connected QTableView
displays the empty rows as you described.
Probably QTableView gets confused, because it does not get a signal
about the deleted or added row explicitly.
There is an ugly workaround:
yourtableview->setModel(0);
yourmodel->setQuery/select();
yourtableview->setModel(yourmodel);
A better "solution" (workaround) is, to operate only on the model itself
(insertRow/removeRow/setData). But then you have move from
QSqlQueryModel to QSqlTableModel.
Greetings
Niklas
--
[ signature omitted ]
Message 12 in thread
> It works only flawlessly, if I operate ONLY on the model.
Yes, I came to the same conclusion.
> There is an ugly workaround:
> yourtableview->setModel(0);
> yourmodel->setQuery/select();
> yourtableview->setModel(yourmodel);
Thanks, works for me. Ugly, but not butt-ugly. :-)
> A better "solution" (workaround) is, to operate only on the model itself
> (insertRow/removeRow/setData). But then you have move from
> QSqlQueryModel to QSqlTableModel.
Unfortunately not an option for me.
Thanks,
Guido
--
[ signature omitted ]