PDA

View Full Version : QGraphicsview size is 30 x 100



szisziszilvi
19th May 2011, 12:28
Hi,

I have the very same problem described here:
http://stackoverflow.com/questions/5103613/getting-the-size-of-a-qgraphicsview

I would like to get the size of the QGraphicsView placen on the ui. Its size is not constant az it is in a layout. You can see in the attechment what I have now. Unfortunatelly I constantly get 30 as height and 100 as width. Where can I have a correct value? If I break teh layout the very same code works fine but it is not stretchable then.

wysota
21st May 2011, 00:25
You are probably asking for the size too early. Size of widgets is undetermined until they are shown for the first time. Move your code to after the widget is shown (to showEvent() or later) and it will work.

szisziszilvi
23rd May 2011, 07:37
Why does it work then if the very same widget is out of a layout?
This is my code:

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString qs;
qs.append("height = " + QString::number(ui->graphicsView->height()));
qs.append("\nwidth = " + QString::number(ui->graphicsView->width()));
ui->labelStatus->setText(qs);
}

If I brake the layout the code works fine. If I put graphicsView and labelStatus into layout it wil b wrong.

wysota
23rd May 2011, 15:44
Why does it work then if the very same widget is out of a layout?
Because your widget doesn't get resized by the layout when it is being shown for the first time.

szisziszilvi
24th May 2011, 08:21
Hm, ok, I see. But where can I put then the lines that get the size? Or shall I connect it maybe with some showing event? I can't find a signal for that. In other words: how do I know that a widget placed on the ui has been resized?

Here I attach a very small project that contains nothing else than the discussed problem.

SixDegrees
24th May 2011, 08:30
See QWidget::ensurePolished(). Don't call it; read the documentation.

wysota
24th May 2011, 08:36
I think ensurePolished() is too early. I think it's best to retrieve the size in the resize event of the graphics view.

szisziszilvi
24th May 2011, 11:01
can you help me on where to reimplement QGraphichsView's resizeEvent function? It is possible to reimplement MainWindow's, but that is of course not the wanted one.

wysota
24th May 2011, 11:10
can you help me on where to reimplement QGraphichsView's resizeEvent function? It is possible to reimplement MainWindow's, but that is of course not the wanted one.

Since you posted this thread in "Qt Programming" and not in "Newbie", I'm sure you have basic C++ abilities and you're able to work with Qt reference manual and eventually you'll come up with a solution on how to handle the event.

szisziszilvi
24th May 2011, 12:43
maybe I'm wrong I thought "newbe" section is rather for "is it possible with qt?" or "I have problems with installing qt" or things like that, so people who are really taking their very first steps. That is why I posted this here. Anyway I'm wondering how I got the "intermediate user" title. Does it come simply with time? :)

wysota
24th May 2011, 14:56
maybe I'm wrong I thought "newbe" section is rather for "is it possible with qt?" or "I have problems with installing qt" or things like that, so people who are really taking their very first steps.
If you don't know how to handle an event then you are taking your first steps, as far as I'm concerned.


Anyway I'm wondering how I got the "intermediate user" title. Does it come simply with time? :)
No, with amount of posts you have. It's not very representative that's why we also have this "reputation" thingy.