PDA

View Full Version : Disappearing content of QMainWindow



Antares
8th April 2014, 15:37
Hello,
I am porting some code from Qt3 to Qt4. I have a form which uses a QtMainWindow, this is showing some canvas obtained with QTRoot (I think this is not important for the bug I am going to explain).
In the constructor the canvas is added to the QtMainWindow, then another class is using this to show some histograms. When I run the executable I see that when I try to plot the histograms, they are correctly showed for a small fraction of second, then they disappear. To show them again I must click inside the QMainWindow where the canvas is put, but if I do something outside then they disappear again. I think this means that the histograms are showed just if the canvas is selected. I tried to solve this with a lot of commands like raise() and so on, but the problem is still occurring.

I can put some simplified code lines to help myself with the explanation:



HistogramView::HistogramView(...)
:QMainWindow() {
MyQRootCanvas *my_canvas = new MyQRootCanvas( frame, "my_canvas" );
vboxLayout->addWidget( my_canvas );
}


Then the class which calls HistogramView is calling the command:



histogramViewList.push_back( new HistogramView(...) ) {
histogramViewList.back()->show();
}


The show() command is showing the QmainWindow, the histogram is showed for a very small time and disappears, and appears again just if I click in the canvas, as I described before.
I did not write the code myself, I am just trying to port it to Qt4.

I really say thank you to anybody who can help me solving this problem or gives me any suggestion.

anda_skoa
8th April 2014, 17:35
What widgets is "vboxLayout" managing?
Is it the layout of "frame"?
If so, is frame the main window's central widget or part of another layout?

Cheers,
_

wysota
9th April 2014, 09:51
What is the definition of MyQRootCanvas?

Antares
9th April 2014, 13:00
Thank you very much for the help

Added after 5 minutes:

This code is inside setupUi(QMainWindow* HistogramViewBase):



widget = new QWidget(HistogramViewBase);
frame = new Q3Frame(widget);
vboxLayout = new QVBoxLayout(frame);
my_canvas = new TQRootCanvas(frame);
sizePolicy4.setHeightForWidth(m_canvas->sizePolicy().hasHeightForWidth());
my_canvas->setSizePolicy(sizePolicy4);
vboxLayout->addWidget(m_canvas);



Hello, here it is the definition,



void MyQRootCanvas::mouseMoveEvent(QMouseEvent *e) {
TQRootCanvas::mouseMoveEvent(e);
if (e) {
TCanvas *the_canvas=::getCanvas(this);
if (the_canvas) {
PadRestore save_pad;
gPad = the_canvas->GetSelectedPad();
TObject *selected = the_canvas->GetSelected();
if (selected) {
const char *message_text = NULL;
if (!selected->InheritsFrom(TVirtualPad::Class())) {
message_text = selected->GetObjectInfo(e->x(), e->y());
}
QString message;
if (selected->InheritsFrom(TNamed::Class())) {
// message = static_cast<TNamed *>(selected)->GetTitle();
// message += " [";
message += static_cast<TNamed *>(selected)->GetName();
message += " : ";
// message += "] : ";
}
if (message_text) {
message+=message_text;
}
emit statusMessage(message);
} ...


Anyway I don't think the problem is inside here..

anda_skoa
22nd April 2014, 12:57
This code is inside setupUi(QMainWindow* HistogramViewBase):



widget = new QWidget(HistogramViewBase);
frame = new Q3Frame(widget);
vboxLayout = new QVBoxLayout(frame);
my_canvas = new TQRootCanvas(frame);
sizePolicy4.setHeightForWidth(m_canvas->sizePolicy().hasHeightForWidth());
my_canvas->setSizePolicy(sizePolicy4);
vboxLayout->addWidget(m_canvas);



The frame has a layout and the canvas was added to it, this is good.
What is missing here is the layout of "widget" and the frame being added to it.

Is that further down in the code of setupUi?
Is widget then set as HistogramViewBase's centralWidget?

Make sure that when you open the .ui file in Qt Designer, that none of the widget that are containers are showing the "broken layout" icon.

Cheers,
_

Antares
23rd April 2014, 13:06
Thank you very much for your suggestion. Anyway, everything seems to be ok, I can see:



vboxLayout = new QVBoxLayout(widget);
...
HistogramViewBase->setCentralWidget(widget);


and no broken layouts...
Do you have any other suggestion?

Thank you very much

anda_skoa
23rd April 2014, 15:20
And the frame has been added to vboxLayout?

Can you attach the .ui file and the generated header?

If you add a label instead of the canvas, does it stay visible?

Cheers,
_

Antares
24th April 2014, 12:30
And the frame has been added to vboxLayout?

Can you attach the .ui file and the generated header?

If you add a label instead of the canvas, does it stay visible?

Cheers,
_


I have attached the files. What do you mean to add a label instead of a canvas?
Thank you very much