Results 1 to 15 of 15

Thread: QGraphicsScene Position Problem

  1. #1
    Join Date
    May 2009
    Posts
    129

    Default QGraphicsScene Position Problem

    I added line edit, pushbutton,label to QGraphics View..

    But the position of scene is mid of the QGraphicsView..

    How do i change the the position of scene in QGraphics View..

    I am trying with
    Qt Code:
    1. QGraphicsScene *scene= new QGraphicsScene(this);
    2. ui->graphicsView->setScene(scene);
    3. ui->graphicsView->setCacheMode(QGraphicsView::CacheBackground);
    4. Ui_Form *m_ui = new Ui_Form;
    5. QWidget *wid = new QWidget;
    6. m_ui->setupUi(wid);
    7. QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget;
    8. QLabel *label = new QLabel;
    9. label->setText("Hello World !!!");
    10. QPushButton *button = new QPushButton;
    11. button->setText("dfgdfgdsg");
    12. QLineEdit *line = new QLineEdit;
    13. line->setFocus();
    14. proxy =scene->addWidget(line);
    15. label->setScaledContents(true);
    16. proxy = scene->addWidget(button);
    17. proxy = scene->addWidget(label);
    18. scene->addRect(QRectF(0, 0, 5, 30))->setBrush(Qt::green);
    19. ui->graphicsView->setScene(scene);
    To copy to clipboard, switch view to plain text mode 

    Adavance Thanks

    Yuvaraj R

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene Position Problem

    Use:
    Qt Code:
    1. setAlignment(Qt::Alignment);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2009
    Posts
    129

    Default Re: QGraphicsScene Position Problem

    For this one is i have include any thing,

    Because i am getting errors. like.


    Qt Code:
    1. error: expected primary-expression before ')' token..
    To copy to clipboard, switch view to plain text mode 
    And one more..

    for Qlabel and pushbutton, i am getting background shadow, please look at attached image.


    Thanks

    Yuvaraj R
    Attached Images Attached Images

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene Position Problem

    error: expected primary-expression before ')' token..
    and it will suggest a line number of the file ...
    send that line also ... u may miss ; or , or any thing
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    May 2009
    Posts
    129

    Default Re: QGraphicsScene Position Problem

    ok..

    It is showing error at line number 46

    Here i post my code.
    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. #include "ui_form.h"
    4. #include<QGraphicsScene>
    5. #include <QGraphicsProxyWidget>
    6. #include <QLabel>
    7. #include <QPushButton>
    8. #include <QLineEdit>
    9. #include <QMessageBox>
    10. QLabel *label,*label1;
    11. QPushButton *button;
    12. QLineEdit *line,*line1;
    13. Widget::Widget(QWidget *parent)
    14. : QWidget(parent), ui(new Ui::WidgetClass)
    15. {
    16. ui->setupUi(this);
    17. QGraphicsScene *scene= new QGraphicsScene(this);
    18. ui->graphicsView->setScene(scene);
    19. ui->graphicsView->setCacheMode(QGraphicsView::CacheBackground);
    20. Ui_Form *m_ui = new Ui_Form;
    21. QWidget *wid = new QWidget;
    22. m_ui->setupUi(wid);
    23. QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget;
    24. QLabel *label = new QLabel;
    25. label->setText("User Name");
    26. QLabel *label1 = new QLabel;
    27. label1->setText("PassWord");
    28. label1->setGeometry(0,40,50,20);
    29. proxy = scene->addWidget(label1);
    30. QPushButton *button = new QPushButton;
    31. button->setText("dfgdfgdsg");
    32. label->setGeometry(0,0,50,20);
    33. QLineEdit *line = new QLineEdit;
    34. line->setGeometry(60,0,100,20);
    35. QLineEdit *line1 = new QLineEdit;
    36. line1->setGeometry(60,40,100,20);
    37. proxy =scene->addWidget(line);
    38. proxy =scene->addWidget(line1);
    39. button->setGeometry(30, 80,50,50);
    40. proxy = scene->addWidget(button);
    41. proxy = scene->addWidget(label);
    42. scene->addRect(QRectF(200, 0, 100, 100))->setBrush(Qt::green);
    43. scene->setFocus();
    44. line->setEnabled(true);
    45. ui->graphicsView->setScene(scene);
    46. ui->graphicsView->setAlignment(Qt::Alignment);
    47. QObject::connect(button,SIGNAL(clicked()),this,SLOT(show_message1()));
    48.  
    49.  
    50. }
    51.  
    52. Widget::~Widget()
    53. {
    54. delete ui;
    55. }
    56. void Widget::show_message1()
    57. {
    58. QMessageBox::information(0,"",QString(line->text()));
    59. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene Position Problem

    u have to give any one of this
    Qt::AlignLeft or Qt::AlignRight or Qt::AlignHCenter or Qt::AlignJustify

    and not Qt::Alignment
    change ui->graphicsView->setAlignment(Qt::Alignment);
    "Behind every great fortune lies a crime" - Balzac

  7. #7
    Join Date
    May 2009
    Posts
    129

    Default Re: QGraphicsScene Position Problem

    Thanks for your reply..


    Previously i gave like that only..

    It showed the Label, line edit at ccentre left of Graphics view


    Any idea ?


    Thanks

    Yuvaraj R

  8. #8
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene Position Problem

    why you are adding QWidgets like this ...
    group the whole lineEdit and QPushButton into single QGroupBox
    Qt Code:
    1. QVBoxLayout *layoout = new QVBoxLayout;
    2. layoout->addWidget(pushButton);
    3. layoout->addWidget(lineEdit);
    4. groupBox->setLayout(layoout);
    To copy to clipboard, switch view to plain text mode 

    and then add the group box to proxy widget
    Qt Code:
    1. QGraphicsProxyWidget *proxy = scene->addWidget(groupBox);
    2. proxy->setPos(x,y); //position where u want in scene
    To copy to clipboard, switch view to plain text mode 
    "Behind every great fortune lies a crime" - Balzac

  9. #9
    Join Date
    May 2009
    Posts
    129

    Default Re: QGraphicsScene Position Problem

    Thanks

    Have u seen attched image..

    I am getting the background show for Qlabel, Qlineedit..


    and one more thing ,if use the drived class slot the application crashing,but not for Base class

    slots


    Thanks

    Yuvaraj R

  10. #10
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene Position Problem

    and one more thing ,if use the drived class slot the application crashing,but not for Base class

    slots
    can u explain more in detail .. i cant get it ..
    "Behind every great fortune lies a crime" - Balzac

  11. #11
    Join Date
    May 2009
    Posts
    129

    Default Re: QGraphicsScene Position Problem

    In above code if i click the button application is crashing, but if use the Close() slot ,application is not crashing.

    If i set the
    Qt Code:
    1. proxy->setPos(0,0)
    To copy to clipboard, switch view to plain text mode 
    also it is displaying mid of the Qgraphics View

    Sorry for my English


    Thanks

    Yuvaraj R

  12. #12
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene Position Problem

    also it is displaying mid of the Qgraphics View
    no it wont ..
    see you should set geometrical value to QGraphicsScene
    ex:
    Qt Code:
    1. QRectF bounds(0, 0, 530, 305);
    2. scene = new QGraphicsScene(bounds, this);
    To copy to clipboard, switch view to plain text mode 

    now the scene having a geometry of (0, 0, 530, 305)
    now set the proxy item any where between the scene coordinates ..
    for ex:
    to set in middle
    proxy->setPos(265, 153)
    in top left
    proxy->setPos(0,0)
    in top right
    proxy->setPos(500, 0)
    in bottom right
    proxy->setPos(500, 280)

    EDIT: check the link
    http://doc.trolltech.com/4.3/coordsys.html
    "Behind every great fortune lies a crime" - Balzac

  13. #13
    Join Date
    May 2009
    Posts
    129

    Default Re: QGraphicsScene Position Problem

    Thanks for your reply

    please pardon me, i had set the wrong align ment in UI... That why i didn't work..


    my next thing is background shodow for Qlabel, Button.

    Thanks

    Yuvaraj R

  14. #14
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene Position Problem

    Quote Originally Posted by addu View Post
    Qt Code:
    1. ui->graphicsView->setAlignment(Qt::Alignment);
    To copy to clipboard, switch view to plain text mode 
    Thasss cool,

  15. #15
    Join Date
    May 2009
    Posts
    129

    Default Re: QGraphicsScene Position Problem

    Can anybody suggest me..


    Why,when adding the Label of push button to QGraphicsView.. It displaying with background

    like in attached images..

    please help avoid the background..


    Thanks

    Yuvaraj R
    Attached Images Attached Images

Similar Threads

  1. Replies: 1
    Last Post: 2nd September 2009, 14:07
  2. Position in a QPixMap created from a QGraphicsScene
    By stevel in forum Qt Programming
    Replies: 8
    Last Post: 8th April 2009, 22:39
  3. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  4. SVG Generation Problem
    By Jime22 in forum Qt Programming
    Replies: 0
    Last Post: 30th April 2008, 22:49
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.