Results 1 to 11 of 11

Thread: QGraphicsview size is 30 x 100

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsview size is 30 x 100

    Hi,

    I have the very same problem described here:
    http://stackoverflow.com/questions/5...-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.
    Attached Images Attached Images
    Szilvi

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsview size is 30 x 100

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsview size is 30 x 100

    Why does it work then if the very same widget is out of a layout?
    This is my code:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. QString qs;
    7. qs.append("height = " + QString::number(ui->graphicsView->height()));
    8. qs.append("\nwidth = " + QString::number(ui->graphicsView->width()));
    9. ui->labelStatus->setText(qs);
    10. }
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsview size is 30 x 100

    Quote Originally Posted by szisziszilvi View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsview size is 30 x 100

    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.
    Attached Files Attached Files
    Szilvi

  6. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsview size is 30 x 100

    See QWidget::ensurePolished(). Don't call it; read the documentation.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsview size is 30 x 100

    I think ensurePolished() is too early. I think it's best to retrieve the size in the resize event of the graphics view.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsview size is 30 x 100

    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.
    Szilvi

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsview size is 30 x 100

    Quote Originally Posted by szisziszilvi View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsview size is 30 x 100

    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?
    Szilvi

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsview size is 30 x 100

    Quote Originally Posted by szisziszilvi View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. [QGraphicsView] Size stretch
    By bspitz in forum Qt Programming
    Replies: 4
    Last Post: 10th May 2011, 09:23
  2. QGraphicsView and QWebView size question
    By MarkoSan in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2009, 01:25
  3. How to increase size of QGraphicsView Dynamically
    By Kingofhearts_sri in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2009, 08:54
  4. Setting the scene size in QGraphicsView
    By Valheru in forum Newbie
    Replies: 5
    Last Post: 11th November 2007, 15:03
  5. Size of QGraphicsView
    By IsleWitch in forum Newbie
    Replies: 10
    Last Post: 10th October 2007, 12:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.