Results 1 to 3 of 3

Thread: Problems with QGraphicsView resizing.

  1. #1
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Problems with QGraphicsView resizing.

    I need to write a QDialog that shows some QGraphicsItems so I thought I'd just add a QGraphicsView widget to the dialog box;

    here is the code:

    Qt Code:
    1. #include "answerdialog.h"
    2. #include "ui_answerdialog.h"
    3.  
    4. AnswerDialog::AnswerDialog(QWidget *parent) :
    5. QDialog(parent),
    6. m_ui(new Ui::AnswerDialog)
    7. {
    8. m_ui->setupUi(this);
    9. scene = new QGraphicsScene(0,0,this->width(),this->height());
    10. scene->setBackgroundBrush(QBrush(QColor(23,23,23)));
    11. m_ui->gvDraw->setScene(scene);
    12. m_ui->gvDraw->setFixedSize(450,220);
    13. }
    14.  
    15. void AnswerDialog::Render(){
    16. QFont font("DejaVu Sans",18,QFont::Normal,false);
    17. scene->addText(Message,font);
    18. }
    19.  
    20. void AnswerDialog::resizeEvent(QResizeEvent *event){
    21. m_ui->gvDraw->fitInView(scene->sceneRect(),Qt::KeepAspectRatioByExpanding);
    22. }
    23.  
    24. AnswerDialog::~AnswerDialog()
    25. {
    26. delete m_ui;
    27. }
    28.  
    29. void AnswerDialog::changeEvent(QEvent *e)
    30. {
    31. QDialog::changeEvent(e);
    32. switch (e->type()) {
    33. case QEvent::LanguageChange:
    34. m_ui->retranslateUi(this);
    35. break;
    36. default:
    37. break;
    38. }
    To copy to clipboard, switch view to plain text mode 

    This is the code that I use to code this class:
    Qt Code:
    1. AnswerDialog ans;
    2. ans.setMessage("Hello World");
    3. ans.Render();
    4. ans.exec();
    To copy to clipboard, switch view to plain text mode 

    The problem that I have is that when the dialog first appears the text look really really small then as soon as I resize the window, it's then that words take their real size. The size remains the same after that. I've tried using this line:
    m_ui->gvDraw->fitInView(scene->sceneRect(),Qt::KeepAspectRatioByExpanding);
    in the render function as well but the result is the same.

    It seems like unless the command is called with dialog allready shown (and by shown I mean visible on the screen) then the command is inefective.

    All I want is to show a message and a couple of QGraphicsItems. Is there anyways for the items to be shown in regular size just as soon as the dialog pops up?

    Thanks for any help.

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

    Default Re: Problems with QGraphicsView resizing.

    In their constructor widgets don't have the size determined yet. You are setting the scene size to the size of the widget, which is completely bogus. You should do that in showEvent() instead.
    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
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems with QGraphicsView resizing.

    Thank you very much.

    That worked perfecty.

Similar Threads

  1. Resizing in QGraphicsView
    By A.H.M. Mahfuzur Rahman in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2009, 09:39
  2. Problems resizing QWidget & Phonon
    By gmclachl in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 16:32
  3. Problems of embedded QWebView in QGraphicsView
    By naruto_9w in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2009, 15:22
  4. Bug in QGraphicsView? ScrollBar problems
    By estanisgeyer in forum Qt Programming
    Replies: 7
    Last Post: 13th March 2008, 17:44
  5. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 22:54

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.