patrik08
17th May 2007, 12:28
I have two mysql connection on QMainWindow to load
i call a waiting dialog on this way:
Preload *waiter = new Preload(0,tr("Connect to host %1").arg(OneVar["dbhost1"]));
waiter->show();
/// waiter->exce();
qApp->processEvents();
/* Preload( int millisec to self close or 0 null to command close ,texttodisplay); */
if i switsch Preload to QDialog the progess bar running from 0-100 and back
just to mysql is connected .. and
i close preload
waiter->SettoClose(); and QDialog stay open ... infinite ... to wait exce int ....
if i switsch Preload to QWidget is open and close
but the progess bar stay on start and event is not processed by calling qApp->processEvents() why?
class Preload : public QWidget
{
Q_OBJECT
//
public:
Preload( int msec , const QString tex );
void SettoClose();
protected:
QPixmap display;
QString textd;
int timeemust;
bool selfclose;
int r_start;
int r_stop;
int r_status;
void paintEvent(QPaintEvent *e);
////void resizeEvent( QResizeEvent * );
private:
signals:
public slots:
void Increment();
Preload::Preload( int msec , const QString tex )
{
//////////QApplication::setOverrideCursor(QCursor(Qt::WaitCu rsor));
display = QPixmap(":/img/about_as_image.png");
textd = tex;
if (msec !=0) {
selfclose = true;
timeemust = msec;
} else {
selfclose = false;
timeemust = 1200;
}
QRect screenSize = qApp->desktop()->availableGeometry();
setWindowFlags ( Qt::Popup );
///////////qDebug() << "### screenSize -> " << screenSize;
r_start = 33;
r_status = r_start;
r_stop = 469;
////////////display = QPixmap("test.png");
QSize actual_result = display.size();
resize(actual_result);
qApp->processEvents();
Increment();
qApp->processEvents();
}
void Preload::paintEvent(QPaintEvent *e)
{
/////qDebug() << "### nullimage -> " << display.isNull();
QColor textColor = QColor(147,147,147);
QColor fillrectcolor = Qt::red;
QColor shapepicture = Qt::white;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.drawPixmap(0,0,display);
QPen pen;
pen.setStyle( Qt::SolidLine );
pen.setWidth( 3 );
pen.setColor(fillrectcolor);
painter.setPen( pen);
painter.drawLine (QPoint(r_start,96),QPoint(r_status,96));
pen.setWidth( 2 );
pen.setColor(textColor);
QFont f( "arial", 12, QFont::Bold );
painter.setFont( f );
painter.setPen( pen);
QFontMetrics fm = painter.fontMetrics();
int largo = fm.width(textd);
painter.drawText(QPointF((display.width() / 2) - (largo / 2),118),textd);
}
void Preload::SettoClose()
{
selfclose = true;
close();
}
void Preload::Increment()
{
if (r_status > r_stop) {
if (selfclose) {
close();
return;
} else {
r_status = r_start;
}
}
int distance = r_stop - r_start;
int piesesec = timeemust / distance; /* 100% */
r_status = r_status + 1;
update();
QTimer::singleShot(piesesec, this, SLOT(Increment()));
qApp->processEvents();
}
i call a waiting dialog on this way:
Preload *waiter = new Preload(0,tr("Connect to host %1").arg(OneVar["dbhost1"]));
waiter->show();
/// waiter->exce();
qApp->processEvents();
/* Preload( int millisec to self close or 0 null to command close ,texttodisplay); */
if i switsch Preload to QDialog the progess bar running from 0-100 and back
just to mysql is connected .. and
i close preload
waiter->SettoClose(); and QDialog stay open ... infinite ... to wait exce int ....
if i switsch Preload to QWidget is open and close
but the progess bar stay on start and event is not processed by calling qApp->processEvents() why?
class Preload : public QWidget
{
Q_OBJECT
//
public:
Preload( int msec , const QString tex );
void SettoClose();
protected:
QPixmap display;
QString textd;
int timeemust;
bool selfclose;
int r_start;
int r_stop;
int r_status;
void paintEvent(QPaintEvent *e);
////void resizeEvent( QResizeEvent * );
private:
signals:
public slots:
void Increment();
Preload::Preload( int msec , const QString tex )
{
//////////QApplication::setOverrideCursor(QCursor(Qt::WaitCu rsor));
display = QPixmap(":/img/about_as_image.png");
textd = tex;
if (msec !=0) {
selfclose = true;
timeemust = msec;
} else {
selfclose = false;
timeemust = 1200;
}
QRect screenSize = qApp->desktop()->availableGeometry();
setWindowFlags ( Qt::Popup );
///////////qDebug() << "### screenSize -> " << screenSize;
r_start = 33;
r_status = r_start;
r_stop = 469;
////////////display = QPixmap("test.png");
QSize actual_result = display.size();
resize(actual_result);
qApp->processEvents();
Increment();
qApp->processEvents();
}
void Preload::paintEvent(QPaintEvent *e)
{
/////qDebug() << "### nullimage -> " << display.isNull();
QColor textColor = QColor(147,147,147);
QColor fillrectcolor = Qt::red;
QColor shapepicture = Qt::white;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.drawPixmap(0,0,display);
QPen pen;
pen.setStyle( Qt::SolidLine );
pen.setWidth( 3 );
pen.setColor(fillrectcolor);
painter.setPen( pen);
painter.drawLine (QPoint(r_start,96),QPoint(r_status,96));
pen.setWidth( 2 );
pen.setColor(textColor);
QFont f( "arial", 12, QFont::Bold );
painter.setFont( f );
painter.setPen( pen);
QFontMetrics fm = painter.fontMetrics();
int largo = fm.width(textd);
painter.drawText(QPointF((display.width() / 2) - (largo / 2),118),textd);
}
void Preload::SettoClose()
{
selfclose = true;
close();
}
void Preload::Increment()
{
if (r_status > r_stop) {
if (selfclose) {
close();
return;
} else {
r_status = r_start;
}
}
int distance = r_stop - r_start;
int piesesec = timeemust / distance; /* 100% */
r_status = r_status + 1;
update();
QTimer::singleShot(piesesec, this, SLOT(Increment()));
qApp->processEvents();
}