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:
#include "answerdialog.h"
#include "ui_answerdialog.h"
AnswerDialog
::AnswerDialog(QWidget *parent
) : m_ui(new Ui::AnswerDialog)
{
m_ui->setupUi(this);
m_ui->gvDraw->setScene(scene);
m_ui->gvDraw->setFixedSize(450,220);
}
void AnswerDialog::Render(){
scene->addText(Message,font);
}
m_ui->gvDraw->fitInView(scene->sceneRect(),Qt::KeepAspectRatioByExpanding);
}
AnswerDialog::~AnswerDialog()
{
delete m_ui;
}
void AnswerDialog
::changeEvent(QEvent *e
) {
switch (e->type()) {
m_ui->retranslateUi(this);
break;
default:
break;
}
#include "answerdialog.h"
#include "ui_answerdialog.h"
AnswerDialog::AnswerDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::AnswerDialog)
{
m_ui->setupUi(this);
scene = new QGraphicsScene(0,0,this->width(),this->height());
scene->setBackgroundBrush(QBrush(QColor(23,23,23)));
m_ui->gvDraw->setScene(scene);
m_ui->gvDraw->setFixedSize(450,220);
}
void AnswerDialog::Render(){
QFont font("DejaVu Sans",18,QFont::Normal,false);
scene->addText(Message,font);
}
void AnswerDialog::resizeEvent(QResizeEvent *event){
m_ui->gvDraw->fitInView(scene->sceneRect(),Qt::KeepAspectRatioByExpanding);
}
AnswerDialog::~AnswerDialog()
{
delete m_ui;
}
void AnswerDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
To copy to clipboard, switch view to plain text mode
This is the code that I use to code this class:
AnswerDialog ans;
ans.setMessage("Hello World");
ans.Render();
ans.exec();
AnswerDialog ans;
ans.setMessage("Hello World");
ans.Render();
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.
Bookmarks