PDA

View Full Version : Make an example of QT in MDI



avis_phoenix
13th June 2006, 15:42
in the examples of QT is one is called "Paint and Plug", wanted to pass it to MDI, then I made a class of QScrollArea type but don't show me that I specify to him in setWidget, then I do not know in which it mistakes to me or How I can pass it to MDI?

Big Duck
13th June 2006, 19:11
It'd be helpfull if you could post some code to let us understand better what your trying to do.

here's the code from: http://doc.trolltech.com/4.1/qscrollarea.html



QLabel *imageLabel = new QLabel;
QImage image("happyguy.png");
imageLabel->setPixmap(QPixmap::fromImage(image));

scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);


Presumably you can add a widget to the mdi. Perhaps you need to pass some p ointers between widgets and the MDI.

avis_phoenix
15th June 2006, 15:59
well i make a two class

class Win: public QScrollArea
{
...
}
class paintArea: public QWidget
{
...
private:
void paintEvent(QEvent *event);
QImage Paper;
...
}

in the constructor of win class:

Win::Win(QWidget *parent): QScrollArea(parent)
{
paintArea *paper = new paintArea;
setBackgroundRole(QPalette::Dark);
setWidget(paper);
...
}
in the constructor of paintarea class i define a QImage name's Paper. in the function apintEvent of paintarea draw the image Paper.

When i create a mdichild with win class show a window with Dark Background, but never show the paint area,What is my mistake?

fullmetalcoder
15th June 2006, 16:22
When i create a mdichild with win class show a window with Dark Background, but never show the paint area,
What you're saying doesn't make sense! If you see a window with dark background then it is what you call a paint area...

Big Duck
15th June 2006, 17:41
in the MDI example from : qt4 docs


MdiChild *child = createMdiChild();
child->newFile();
child->show();


I am a QT beginner, but how I use the documentation examples is to copy code and delete all the code that I dont need. This makes me understand what code is needed to make something work.

I dont think you use PaintEvent to draw the image. Sorry I cant help more...

fullmetalcoder
16th June 2006, 08:35
in the constructor of win class:

Win::Win(QWidget *parent): QScrollArea(parent)
{
paintArea *paper = new paintArea;
setBackgroundRole(QPalette::Dark);
setWidget(paper);
...
}
What is my mistake?

1) Using setWidget() is wrong... your paint area becomes the only child of the scrollarea so there can't be any MDI... :rolleyes:
2) If nothing appear except a background there can be two reasons : paintArea is not explicitely shown or its paintEvent() is not working properly...
3) If MDI is what you trully want then why are you using QScrollArea and not QWorkspace??? :confused:
4) Hope this helps... :)

avis_phoenix
16th June 2006, 20:07
But the mdi child is win class not a paintarea, in another class use a QWorkspace for make mdi this window and mdichild a win class.

avis_phoenix
19th June 2006, 17:11
well i found mi error, was a stupid error, only change that:

Win::Win(QWidget *parent): QScrollArea(parent)
{
paintArea *paper = new paintArea;
setBackgroundRole(QPalette::Dark);
setWidget(paper);
paper->show();
...
}

that's all

jpn
19th June 2006, 19:30
Hmm, there's most likely something wrong with your widgets' parent-child relationships (QScrollArea should reparent the "paint area" widget correctly during setWidget(), though). You shouldn't have to explicitly call show() in a situation like yours. Which exact version of Qt is this?

avis_phoenix
20th June 2006, 16:07
Well, but without show() don't show the widget in QScrollArea, my version of QT is 4.1.2