Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, March 2002
Dialog problems (Qt 2.3.1, X11)


Message 1 in thread

Hi!

I am trying to write my own QProgressDialog replacement for the case
when I do not know the total amount of things that I need to count in
advance, showing a text label that would count upwards. However, I
cannot get it to work, the dialog simply will not display at all. This
is my class:

  class ProgressText : public QSemiModal
  {
      Q_OBJECT
  protected:
      QLabel *progress;
  public:
      ProgressText(QWidget *parent, const char *name, const QString &title);
      void setProgress(int number) { progress->setNum(number); }
  };

with this constructor:

  ProgressText::ProgressText(QWidget *parent, const char *name,
                             const QString &title)
      : QSemiModal(parent, name, true)
  {
      QBoxLayout *vlayout = new QVBoxLayout(this);
      QLabel *t = new QLabel(title, this);
      vlayout->addWidget(t);
      QBoxLayout *hlayout = new QHBoxLayout(vlayout);
      progress = new QLabel("0", this);
      hlayout->addWidget(progress);
      QLabel *l = new QLabel(tr("message(s) read"), this);
      hlayout->addWidget(l);
  }

And here is where I create it:

  progresstext = new ProgressText(this, "progress2", tr("Reading messages"));
  progresstext->setCaption("apptitle");
  progresstext->setEnabled(true);
  progresstext->show();
  progresstext->setFocus();

Everything seems to be created properly (no errors are reported when I
step through the constructor), but I never see the dialog on-screen. I
have fiddled around a bit with the different calls, of the last three
calls I originally only did call show(), adding setEnabled() and
setFocus() did not change anything.

Can anyone spot what I am doing wrong? I have been battling with this
for several hours now without being able to get it to work. I even
checked the sources for QProgressDialog to see if I did something very
much different, but it just seems to call show() to display itself.

I also first tried to have this as a subclass of QDialog, but that
didn't work either.

Any help would be greatly appreciated!

(Oh, yeah, and all this code is GPL'd)
-- 
 [ signature omitted ] 

Message 2 in thread

Isn't the parent widget of ProgressText an object of 
QWorkspace?
If an object of QDialog (or its subclass) is created with a 
 QWorkspace object as its parent, and the QWorkspace object 
has been already shown, the dialog somehow never can be 
visible.

For example:

MyMainWindow::MyMainWindow ()
{
    QVBox* viewBack = new QVBox (this);
    m_ws = new QWorkspace (viewBack);
    setCentralWidget (viewBack);
    QDialog* dlgA = new QDialog (ws, false);
    dlgA->show ();
    ....
}

It makes dlgA visible, but,

void MyMainWindow::slotHoge ()
{
    QDialog* dlgB = new QDialog (m_ws, false);
    dlgB->show ();
    ....
}

dlgB never becomes visible.
You can make dlgB visible by calling dlgB->parentWidget 
()->show (), but I think it would be a BUG of Qt.


Naoyuki


On 2002 March 14 Thursday 05:25, peter karlsson wrote:
> Hi!
>
> I am trying to write my own QProgressDialog replacement
> for the case when I do not know the total amount of
> things that I need to count in advance, showing a text
> label that would count upwards. However, I cannot get it
> to work, the dialog simply will not display at all. This
> is my class:
>
>   class ProgressText : public QSemiModal
>   {
>       Q_OBJECT
>   protected:
>       QLabel *progress;
>   public:
>       ProgressText(QWidget *parent, const char *name,
> const QString &title); void setProgress(int number) {
> progress->setNum(number); } };
>
> with this constructor:
>
>   ProgressText::ProgressText(QWidget *parent, const char
> *name, const QString &title)
>
>       : QSemiModal(parent, name, true)
>
>   {
>       QBoxLayout *vlayout = new QVBoxLayout(this);
>       QLabel *t = new QLabel(title, this);
>       vlayout->addWidget(t);
>       QBoxLayout *hlayout = new QHBoxLayout(vlayout);
>       progress = new QLabel("0", this);
>       hlayout->addWidget(progress);
>       QLabel *l = new QLabel(tr("message(s) read"),
> this); hlayout->addWidget(l);
>   }
>
> And here is where I create it:
>
>   progresstext = new ProgressText(this, "progress2",
> tr("Reading messages"));
> progresstext->setCaption("apptitle");
>   progresstext->setEnabled(true);
>   progresstext->show();
>   progresstext->setFocus();
>
> Everything seems to be created properly (no errors are
> reported when I step through the constructor), but I
> never see the dialog on-screen. I have fiddled around a
> bit with the different calls, of the last three calls I
> originally only did call show(), adding setEnabled() and
> setFocus() did not change anything.
>
> Can anyone spot what I am doing wrong? I have been
> battling with this for several hours now without being
> able to get it to work. I even checked the sources for
> QProgressDialog to see if I did something very much
> different, but it just seems to call show() to display
> itself.
>
> I also first tried to have this as a subclass of QDialog,
> but that didn't work either.
>
> Any help would be greatly appreciated!
>
> (Oh, yeah, and all this code is GPL'd)

Message 3 in thread

IKEGAMI Naoyuki:

> Isn't the parent widget of ProgressText an object of QWorkspace?

My parent widget is a subclass of QMainWindow.

> You can make dlgB visible by calling dlgB->parentWidget
> ()->show (), but I think it would be a BUG of Qt.

That looks like a weird solution. I'll have a look if it helps later.

Anyway, I have put a alpha version of the program up at
http://www.softwolves.pp.se/tmp/turqstat_2.3-alpha.tar.gz
The code in question is in qtprogress.cpp and qtprogress.h, and the dialog
is created from qtgui.cpp in InfoWindow::getProgressText()

To try the code out one needs to try opening something like a local news
spool (File | Open message base).

-- 
 [ signature omitted ]