Results 1 to 3 of 3

Thread: QMdiArea / SubWindow Problem

  1. #1
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QMdiArea / SubWindow Problem

    Hi,

    I am currently working on an MDIbased Project.

    I ahve set up an MDI area, and am working on adding different widgets to it.

    But i am having problems with one of my Widgets. It is a custom codeeditor widget subclassed from QFrame, that contains a QTextEdit and a QWidget in which i draw the linenumbers.

    "My Editor Constructor"
    Qt Code:
    1. TextEditorWidget::TextEditorWidget(QWidget *parent,const QString &file)
    2. : QFrame(parent)
    3. {
    4. setFrameStyle(QFrame::StyledPanel|QFrame::Sunken);
    5. setMidLineWidth(2);
    6.  
    7. editor = new QTextEdit(this);
    8. editor->setAcceptRichText(true);
    9. ...
    10. lineNumbers = new LineNumbers(this);
    11.  
    12. QHBoxLayout *editorLayout = new QHBoxLayout;
    13. editorLayout->setSpacing(0);
    14. editorLayout->addWidget(lineNumbers);
    15. editorLayout->addWidget(editor);
    16. editorLayout->setContentsMargins(0,0,0,0);
    17.  
    18. this->setLayout(editorLayout);
    19. ...
    To copy to clipboard, switch view to plain text mode 

    "My add to MDIarea method"
    Qt Code:
    1. void MainWindow::createEditor()
    2. {
    3. QMdiSubWindow *child = new QMdiSubWindow(componentArea);
    4. TextEditorWidget *editor = new TextEditorWidget(child);
    5.  
    6. child->setWidget(editor);
    7. child->setAttribute(Qt::WA_DeleteOnClose);
    8.  
    9. componentArea->addSubWindow(child);
    10. child->show();
    11. }
    To copy to clipboard, switch view to plain text mode 

    I have done prety much the same with other widgets, but with this one i get the following problems/errors:

    when the method is called the following apears on the console:
    "QMdiArea::addSubWindow: window is already added"

    and The window itself does not get painted properly at first, only after i move it it gets drawn properly. I have attached a screenshot with a before-and-after.

    I just can't figure out why it's giving me problems with this widget, it works fine for a QListwidget subclass and other QFrame sublcasses.

    Maybe someone has already encountered this problem and can point me in the right directions.

    Thanks for reading.

    Eric
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QMdiArea / SubWindow Problem

    try not passing componentArea as parent when you create that QMdiSubWindow

  3. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea / SubWindow Problem

    Why not inherit directly from QMdiSubWindow instead of adding a new QMdiSubWindow initialized with a QFrame?
    QMdiSubWindow does not have all the features of the QFrame?

    Qt Code:
    1. class TextEditor : public QMdiSubWindow {
    2. Q_OBJECT
    3.  
    4. public:
    5. TextEditor(QWidget *parent = 0):QMdiSubWindow(parent) {
    6. setAttribute(Qt::WA_DeleteOnClose);
    7. m_text = new QTextEdit;
    8. layout()->addWidget(m_text);
    9. }
    10. ~TextEditor() {
    11. }
    12.  
    13. private:
    14. QWidget * m_text;
    15. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class MDITextEditor : public QMainWindow {
    2. Q_OBJECT
    3.  
    4. public:
    5.  
    6. MDITextEditor(QWidget *parent = 0):QMainWindow(parent) {
    7. m_area = new QMdiArea;
    8. setCentralWidget(m_area);
    9. createActions();
    10. createMenus();
    11. }
    12.  
    13. ~MDITextEditor(){
    14. }
    15.  
    16. public slots:
    17. void newSubWindow();
    18.  
    19. private:
    20.  
    21. QMdiArea * m_area;
    22. QAction * m_new;
    23. QMenu * m_menu;
    24.  
    25. void createActions() {
    26. m_new = new QAction(this);
    27. m_new->setText(tr("New..."));
    28. connect(m_new, SIGNAL(triggered()), this, SLOT(newSubWindow()));
    29. }
    30. void createMenus() {
    31. m_menu = new QMenu(tr("File"));
    32. m_menu->addAction(m_new);
    33. menuBar()->addMenu(m_menu);
    34. }
    35. };
    36. inline void MDITextEditor::newSubWindow(){
    37. TextEditor * textEditor = new TextEditor;
    38. m_area->addSubWindow(textEditor);
    39. textEditor->show();
    40. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.