Results 1 to 8 of 8

Thread: Disappearing content of QMainWindow

  1. #1
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Disappearing content of QMainWindow

    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:

    Qt Code:
    1. HistogramView::HistogramView(...)
    2. MyQRootCanvas *my_canvas = new MyQRootCanvas( frame, "my_canvas" );
    3. vboxLayout->addWidget( my_canvas );
    4. }
    To copy to clipboard, switch view to plain text mode 

    Then the class which calls HistogramView is calling the command:

    Qt Code:
    1. histogramViewList.push_back( new HistogramView(...) ) {
    2. histogramViewList.back()->show();
    3. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by Antares; 8th April 2014 at 15:50.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Disappearing content of QMainWindow

    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,
    _

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Disappearing content of QMainWindow

    What is the definition of MyQRootCanvas?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Disappearing content of QMainWindow

    Thank you very much for the help


    Added after 5 minutes:


    This code is inside setupUi(QMainWindow* HistogramViewBase):

    Qt Code:
    1. widget = new QWidget(HistogramViewBase);
    2. frame = new Q3Frame(widget);
    3. vboxLayout = new QVBoxLayout(frame);
    4. my_canvas = new TQRootCanvas(frame);
    5. sizePolicy4.setHeightForWidth(m_canvas->sizePolicy().hasHeightForWidth());
    6. my_canvas->setSizePolicy(sizePolicy4);
    7. vboxLayout->addWidget(m_canvas);
    To copy to clipboard, switch view to plain text mode 

    Hello, here it is the definition,

    Qt Code:
    1. void MyQRootCanvas::mouseMoveEvent(QMouseEvent *e) {
    2. TQRootCanvas::mouseMoveEvent(e);
    3. if (e) {
    4. TCanvas *the_canvas=::getCanvas(this);
    5. if (the_canvas) {
    6. PadRestore save_pad;
    7. gPad = the_canvas->GetSelectedPad();
    8. TObject *selected = the_canvas->GetSelected();
    9. if (selected) {
    10. const char *message_text = NULL;
    11. if (!selected->InheritsFrom(TVirtualPad::Class())) {
    12. message_text = selected->GetObjectInfo(e->x(), e->y());
    13. }
    14. QString message;
    15. if (selected->InheritsFrom(TNamed::Class())) {
    16. // message = static_cast<TNamed *>(selected)->GetTitle();
    17. // message += " [";
    18. message += static_cast<TNamed *>(selected)->GetName();
    19. message += " : ";
    20. // message += "] : ";
    21. }
    22. if (message_text) {
    23. message+=message_text;
    24. }
    25. emit statusMessage(message);
    26. } ...
    To copy to clipboard, switch view to plain text mode 

    Anyway I don't think the problem is inside here..
    Last edited by Antares; 9th April 2014 at 13:12.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Disappearing content of QMainWindow

    Quote Originally Posted by Antares View Post
    This code is inside setupUi(QMainWindow* HistogramViewBase):

    Qt Code:
    1. widget = new QWidget(HistogramViewBase);
    2. frame = new Q3Frame(widget);
    3. vboxLayout = new QVBoxLayout(frame);
    4. my_canvas = new TQRootCanvas(frame);
    5. sizePolicy4.setHeightForWidth(m_canvas->sizePolicy().hasHeightForWidth());
    6. my_canvas->setSizePolicy(sizePolicy4);
    7. vboxLayout->addWidget(m_canvas);
    To copy to clipboard, switch view to plain text mode 
    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,
    _

  6. #6
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Disappearing content of QMainWindow

    Thank you very much for your suggestion. Anyway, everything seems to be ok, I can see:

    Qt Code:
    1. vboxLayout = new QVBoxLayout(widget);
    2. ...
    3. HistogramViewBase->setCentralWidget(widget);
    To copy to clipboard, switch view to plain text mode 

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

    Thank you very much

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Disappearing content of QMainWindow

    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,
    _

  8. #8
    Join Date
    Apr 2014
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Disappearing content of QMainWindow

    Quote Originally Posted by anda_skoa View Post
    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
    Attached Files Attached Files

Similar Threads

  1. Sharing same QToolbar amongst multiple QMainWindows
    By Henry Blue Heeler in forum Newbie
    Replies: 8
    Last Post: 31st December 2013, 23:57
  2. Changing QMainWindows backgroundcolor
    By dennis81 in forum Qt Programming
    Replies: 4
    Last Post: 10th October 2012, 12:12
  3. Dragging QDockWidgets between QMainWindows
    By FelixB in forum Newbie
    Replies: 3
    Last Post: 14th October 2011, 07:37
  4. shared QUnstackStack among several QMainWindows ?
    By umanga in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2010, 06:58
  5. How to change between QMainWindows???
    By webquinty in forum Newbie
    Replies: 3
    Last Post: 16th October 2009, 10:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.