Results 1 to 11 of 11

Thread: Size of QGraphicsView

  1. #1
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Size of QGraphicsView

    Hi,

    Is there anyway in which I could set the size of QGraphicsView. I would like it to be, as in the image attached.

    Thank You.
    Attached Images Attached Images

  2. #2
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Size of QGraphicsView

    you can get it using
    size()
    or
    QRectF sceneRect ()

  3. #3
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Size of QGraphicsView

    Thanks Rajesh.

    But size(), doesnt work. I used QRectF sceneRect (), but, no apparent changes occured. The graphicsView stayed the same size, it's occupying the window (as in, there are no spaces at the sides of the graphicsViewer).

  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: Size of QGraphicsView

    Are you using layouts in your window?

  5. #5
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Size of QGraphicsView

    its not clear what you want to do?
    if you want to set initial size of QGraphicsview then you can use sizeHint.

    or

    QGridScene m_scene = new QGraphicsScene(0,0,1000,600,this); // define size here
    graphicsView.setScene(m_scene);

    actually you can not display directly to QGraphicsView, you need to use QGraphicsScene
    eg.
    QGraphicsScene scene;
    scene.addText("Hello, world!");
    QGraphicsView view(&scene);
    view.show();

    no, I am not using layout. but I am writing hand coding. no Qt Designer.

  6. #6
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Size of QGraphicsView

    Yes I'am using layouts.

    Here Is the code, it might give a better picture of what im trying to do:

    Qt Code:
    1. #include <QLabel>
    2. #include <QPushButton>
    3. #include <QGraphicsView>
    4. #include <QLineEdit>
    5. #include <QHBoxLayout>
    6. #include <QVBoxLayout>
    7. #include <QPushButton>
    8. #include <QApplication>
    9. #include <QCheckBox>
    10. #include "browseimages.h"
    11.  
    12. BrowseImages::BrowseImages(QWidget *parent) : QWidget(parent)
    13. {
    14. // Title of the window
    15. this->setWindowTitle("Browse Images");
    16. this->resize(700, 400); // I'm using your old values
    17.  
    18. b_search = new QPushButton(tr("SEARCH"));
    19. b_search->setFixedHeight(40);
    20.  
    21. b_exit = new QPushButton(tr("Exit"));
    22. b_exit->setFixedHeight(40);
    23.  
    24. QHBoxLayout *h_exit = new QHBoxLayout;
    25. h_exit->addStretch();
    26. h_exit->addWidget(b_exit);
    27. h_exit->addStretch();
    28.  
    29. connect(b_exit, SIGNAL(clicked()), qApp, SLOT(quit()));
    30.  
    31. l_welcome = new QLabel(tr("--Browse Images--"));
    32. l_welcome->setFont(QFont("Times", 18, QFont::Bold));
    33. l_welcome->setAlignment(Qt::AlignCenter);
    34.  
    35. g_graphics = new QGraphicsView(this);
    36. g_graphics->scale(50,70);
    37.  
    38.  
    39. v_1->setAlignment(Qt::AlignCenter);
    40. v_1->addSpacing(30);
    41. v_1->addWidget(b_search);
    42.  
    43.  
    44. v_e->setAlignment(Qt::AlignCenter);
    45. v_e->addWidget(b_exit);
    46.  
    47.  
    48. v_g->setAlignment(Qt::AlignCenter);
    49. v_g->addWidget(g_graphics);
    50.  
    51.  
    52. QVBoxLayout *layout_vert = new QVBoxLayout;
    53. layout_vert->setAlignment(Qt::AlignTop);
    54.  
    55. layout_vert->addWidget(l_welcome);
    56. layout_vert->addSpacing(30);
    57. layout_vert->addLayout(v_g);
    58. layout_vert->addSpacing(20);
    59. layout_vert->addLayout(v_1);
    60. layout_vert->addSpacing(20);
    61. layout_vert->addLayout(v_e);
    62. //layout_vert->addLayout(h_exit);
    63.  
    64.  
    65. this->setLayout(layout_vert);
    66.  
    67. }
    To copy to clipboard, switch view to plain text mode 

    Thank You,

  7. #7
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Size of QGraphicsView

    ok, let me check your code.

  8. #8
    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: Size of QGraphicsView

    Oh God, please don't use fixed sizes Attached is the Designer mockup of what you (probably) want. You can either use uic to generate the code used to obtain such a layout or just write the code yourself based on what you see. You might also get rid of those two external spacers as they don't really fit there preventing the graphics view from expanding. It's better to ask the dialog to adjust its just to the graphics view and not to force that empty space on both sides.
    Attached Files Attached Files

  9. The following user says thank you to wysota for this useful post:

    IsleWitch (10th October 2007)

  10. #9
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Size of QGraphicsView

    if you using designer then you can add spacers both side.

  11. The following user says thank you to rajesh for this useful post:

    IsleWitch (10th October 2007)

  12. #10
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Size of QGraphicsView

    Is your problem solved?

    if you doing hand coding then you can use QGridLayout which is easy to set all widget.
    like

    {
    // Title of the window
    setWindowTitle("Browse Images");
    resize(700, 400); // I'm using your old values

    QPushButton *b_search = new QPushButton(tr("SEARCH"));
    QPushButton *b_exit = new QPushButton(tr("Exit"));
    QLabel *l_welcome = new QLabel(tr("--Browse Images--"));
    l_welcome->setFont(QFont("Times", 18, QFont::Bold));
    l_welcome->setAlignment(Qt::AlignCenter);

    QGraphicsView *g_graphics = new QGraphicsView(this);
    g_graphics->scale(50,70);
    QGridLayout *gridLayout = new QGridLayout(this);
    gridLayout->addWidget(l_welcome,0,2,1,4);
    gridLayout->addWidget(g_graphics,1,2,4,5);
    gridLayout->addWidget(b_search,6,3);
    gridLayout->addWidget(b_exit,7,3);
    gridLayout->setColumnMinimumWidth(0,50);
    gridLayout->setColumnMinimumWidth(7,50);
    setLayout(gridLayout);
    connect(b_exit, SIGNAL(clicked()), qApp, SLOT(quit()));
    }

  13. The following user says thank you to rajesh for this useful post:

    IsleWitch (10th October 2007)

  14. #11
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Size of QGraphicsView

    Thank You very much Rajesh and Wysota, I'am still working on it. I'm trying your suggestions, and i will get back to you as soon as i ge the desired result.

    Thanks again for your help

Similar Threads

  1. Simple custom widget won't size properly
    By MrGarbage in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 13:12
  2. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 22:22
  3. Speed, transparency, and drop issues with QGraphicsView
    By jefferai in forum Qt Programming
    Replies: 16
    Last Post: 30th June 2007, 16:14
  4. Replies: 1
    Last Post: 24th October 2006, 16:40
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.