Qt-interest Archive, April 2007
Qt 4.3beta, paintEvent() problem in Windows
Message 1 in thread
Hello!
I'm new in QT and I am with QT4.3beta. I wrote this code for Linux and
it is like a "Hello World" application. In Linux I had no problem, but,
when I run the windows version paintEvent() doesn't come. I'm using Win
Xp and MinGw 5.0. If somebody has an idea about what i'm doing wrong or
what else I need to include to my windows code I'll be very thankyou.
David.
________________________________________________________________________________
uic-qt4 Header:
#ifndef UI_MONOS_H
#define UI_MONOS_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QFrame>
#include <QtGui/QGridLayout>
#include <QtGui/QPushButton>
class Ui_Dialog
{
public:
QGridLayout *gridLayout;
QFrame *Mono2;
QFrame *Mono1;
QPushButton *Botton;
QDialogButtonBox *buttonBox;
void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
gridLayout = new QGridLayout(Dialog);
gridLayout->setSpacing(6);
gridLayout->setMargin(9);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
Mono2 = new QFrame(Dialog);
Mono2->setObjectName(QString::fromUtf8("Mono2"));
Mono2->setFrameShape(QFrame::StyledPanel);
Mono2->setFrameShadow(QFrame::Raised);
gridLayout->addWidget(Mono2, 1, 0, 1, 2);
Mono1 = new QFrame(Dialog);
Mono1->setObjectName(QString::fromUtf8("Mono1"));
Mono1->setFrameShape(QFrame::StyledPanel);
Mono1->setFrameShadow(QFrame::Raised);
gridLayout->addWidget(Mono1, 0, 0, 1, 2);
Botton = new QPushButton(Dialog);
Botton->setObjectName(QString::fromUtf8("Botton"));
gridLayout->addWidget(Botton, 2, 0, 1, 1);
buttonBox = new QDialogButtonBox(Dialog);
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
gridLayout->addWidget(buttonBox, 2, 1, 1, 1);
retranslateUi(Dialog);
QSize size(509, 468);
size = size.expandedTo(Dialog->minimumSizeHint());
Dialog->resize(size);
} // setupUi
void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog",
0, QApplication::UnicodeUTF8));
Botton->setText(QApplication::translate("Dialog", "Pinta
Conchetu'mare", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Dialog);
} // retranslateUi
};
namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui
#endif // UI_MONOS_H
________________________________________________________________________________
Dialog Header:
#include "Monos.h"
#include <QDialog>
class DMonos:public QDialog, private Ui_Dialog
{
Q_OBJECT
public slots:
void otro_slot();
public:
DMonos(QWidget *parent = 0);
};
________________________________________________________________________________
Dialog Source:
#include <QPainter>
#include <QPaintEvent>
#include <QString>
#include "DMonos.h"
DMonos::DMonos(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QObject::connect(Botton, SIGNAL(clicked()), this, SLOT(otro_slot()));
QObject::connect(Botton, SIGNAL(clicked()), Mono2, SLOT(repaint()));
QObject::connect(Botton, SIGNAL(clicked()), Mono1, SLOT(repaint()));
}
QString paso="No paso por Paint!";
void QFrame::paintEvent (QPaintEvent * event)
{
QString nombre;
QPainter* PMapa = new QPainter(this);
QRect rectangulo;
rectangulo = event->rect();
PMapa->setWindow(rectangulo);
nombre = this->objectName();
if (nombre=="Mono1")
{
PMapa->drawLine(0,0,100,100);
}
else if (nombre=="Mono2")
{
PMapa->drawLine(0,100,100,0);
}
PMapa->end();
paso = "Paso por Paint!!!";
}
void DMonos::otro_slot()
{
Botton->setText(paso);
}
--
[ signature omitted ]
Message 2 in thread
Hi,
> I'm new in QT and I am with QT4.3beta. I wrote this code for Linux and
> it is like a "Hello World" application. In Linux I had no problem, but,
> when I run the windows version paintEvent() doesn't come. I'm using Win
> Xp and MinGw 5.0. If somebody has an idea about what i'm doing wrong or
> what else I need to include to my windows code I'll be very thankyou.
Ouch! I would suggest trying to strip down your program before posting
it. In most cases it should be possible to post a complete minimal
example between 10 and 20 lines of code.
There are two reasons for that:
1) Most often you'll find the error during the process of stripping down
the program.
2) If the error it's still there in the minimal program, it's much
easier for subscribers of this list to help you.
I don't understand what you're trying to do in this line:
void QFrame::paintEvent [...]
You should probably declare paintEvent() in the DMonos class and then
define it as :
void DMonos::paintEvent [...]
--
[ signature omitted ]
Message 3 in thread
Hello!
I'm new in QT and I am with QT4.3beta. I wrote this code for Linux and it
is like a "Hello World" application. In Linux I had no problem, but, when
I run the windows version paintEvent() doesn't come. I'm using Win Xp and
MinGw 5.0. If somebody has an idea about what i'm doing wrong or what else
I need to include to my windows code I'll be very thankyou.
David.
________________________________________________________________________________
uic-qt4 Header:
#ifndef UI_MONOS_H
#define UI_MONOS_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QFrame>
#include <QtGui/QGridLayout>
#include <QtGui/QPushButton>
class Ui_Dialog
{
public:
QGridLayout *gridLayout;
QFrame *Mono2;
QFrame *Mono1;
QPushButton *Botton;
QDialogButtonBox *buttonBox;
void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
gridLayout = new QGridLayout(Dialog);
gridLayout->setSpacing(6);
gridLayout->setMargin(9);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
Mono2 = new QFrame(Dialog);
Mono2->setObjectName(QString::fromUtf8("Mono2"));
Mono2->setFrameShape(QFrame::StyledPanel);
Mono2->setFrameShadow(QFrame::Raised);
gridLayout->addWidget(Mono2, 1, 0, 1, 2);
Mono1 = new QFrame(Dialog);
Mono1->setObjectName(QString::fromUtf8("Mono1"));
Mono1->setFrameShape(QFrame::StyledPanel);
Mono1->setFrameShadow(QFrame::Raised);
gridLayout->addWidget(Mono1, 0, 0, 1, 2);
Botton = new QPushButton(Dialog);
Botton->setObjectName(QString::fromUtf8("Botton"));
gridLayout->addWidget(Botton, 2, 0, 1, 1);
buttonBox = new QDialogButtonBox(Dialog);
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
gridLayout->addWidget(buttonBox, 2, 1, 1, 1);
retranslateUi(Dialog);
QSize size(509, 468);
size = size.expandedTo(Dialog->minimumSizeHint());
Dialog->resize(size);
} // setupUi
void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0,
QApplication::UnicodeUTF8));
Botton->setText(QApplication::translate("Dialog", "Pinta!", 0,
QApplication::UnicodeUTF8));
Q_UNUSED(Dialog);
} // retranslateUi
};
namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui
#endif // UI_MONOS_H
________________________________________________________________________________
Dialog Header:
#include "Monos.h"
#include <QDialog>
class DMonos:public QDialog, private Ui_Dialog
{
Q_OBJECT
public slots:
void otro_slot();
public:
DMonos(QWidget *parent = 0);
};
________________________________________________________________________________
Dialog Source:
#include <QPainter>
#include <QPaintEvent>
#include <QString>
#include "DMonos.h"
DMonos::DMonos(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QObject::connect(Botton, SIGNAL(clicked()), this, SLOT(otro_slot()));
QObject::connect(Botton, SIGNAL(clicked()), Mono2, SLOT(repaint()));
QObject::connect(Botton, SIGNAL(clicked()), Mono1, SLOT(repaint()));
}
QString paso="No paso por Paint!";
void QFrame::paintEvent (QPaintEvent * event)
{
QString nombre; QPainter* PMapa = new QPainter(this);
QRect rectangulo;
rectangulo = event->rect();
PMapa->setWindow(rectangulo);
nombre = this->objectName();
if (nombre=="Mono1")
{
PMapa->drawLine(0,0,100,100);
} else if (nombre=="Mono2")
{
PMapa->drawLine(0,100,100,0);
}
PMapa->end(); paso = "Paso por Paint!!!";
}
void DMonos::otro_slot()
{
Botton->setText(paso);
}
--
[ signature omitted ]