Results 1 to 3 of 3

Thread: Attempting to set QLayout on ..., which already has layout

  1. #1
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default Attempting to set QLayout on ..., which already has layout

    Hi, im trying to make program including simple version of model from Basic Sort/File Model Example , but I get an empty window and warning :
    QWidget::setLayout: Attempting to set QLayout "" on EGlowny "", which already has layout

    I've checked code few times and I don't see where I did this.

    Here you have fragment of my code:

    main.cpp

    Qt Code:
    1. #include <QApplication>
    2. #include "eglowny.h"
    3. extern QAbstractItemModel *asd(QObject *parent);
    4. extern void wbaze();
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. EGlowny okno;
    9. okno.setSourceModel(asd(&okno));
    10. okno.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Eglowny.h

    Qt Code:
    1. #ifndef EGLOWNY_H
    2. #define EGLOWNY_H
    3. #include <QMainWindow>
    4. #include <QMenu>
    5. #include <QMenuBar>
    6. #include <QFileDialog>
    7. #include <QMessageBox>
    8. #include <QAbstractItemModel>
    9. #include <QTreeView>
    10. #include <QSortFilterProxyModel>
    11. #include <QComboBox>
    12. #include <QGridLayout>
    13. extern void wbaze(QString &nazwapliku);
    14. extern void zapiszbaze(QString &nazwapliku);
    15. class ToolBar;
    16. QT_FORWARD_DECLARE_CLASS(QMenu)
    17. QT_FORWARD_DECLARE_CLASS(QSignalMapper)
    18. class EGlowny : public QMainWindow
    19. {
    20. Q_OBJECT
    21.  
    22. public:
    23. explicit EGlowny(QWidget *parent = 0);
    24. void setSourceModel(QAbstractItemModel *model);
    25. private:
    26. void pasekmenu();
    27. void wnetrzeokna();
    28. QSortFilterProxyModel *proxyModel;
    29. QGridLayout *proxyLayout;
    30. QTreeView *proxyView;
    31. QLabel *filterPatternLabel;
    32. QLabel *filterColumnLabel;
    33. QLineEdit *filterPatternLineEdit;
    34. QComboBox *filterColumnComboBox;
    35. private slots:
    36.  
    37. void filterREChanged();
    38. void filterColumnChanged();
    39. };
    40. #endif // EGLOWNY_H
    To copy to clipboard, switch view to plain text mode 




    Eglowny.cpp
    Qt Code:
    1. #include "eglowny.h"
    2.  
    3. EGlowny::EGlowny(QWidget *parent) :
    4. QMainWindow(parent)
    5. {
    6. pasekmenu();
    7. wnetrzeokna();
    8. setWindowTitle("Program");
    9. resize(800, 600);
    10. }
    11.  
    12. void EGlowny::wnetrzeokna()
    13. {
    14. proxyModel = new QSortFilterProxyModel;
    15. proxyModel->setDynamicSortFilter(true);
    16.  
    17. proxyView = new QTreeView;
    18. proxyView->setRootIsDecorated(false);
    19. proxyView->setAlternatingRowColors(true);
    20. proxyView->setModel(proxyModel);
    21. proxyView->setSortingEnabled(true);
    22.  
    23. filterPatternLineEdit = new QLineEdit;
    24. filterPatternLabel = new QLabel(tr("Filter Pattern: "));
    25.  
    26. filterColumnComboBox = new QComboBox;
    27. filterColumnComboBox->addItem(tr("1"));
    28. filterColumnComboBox->addItem(tr("2"));
    29. filterColumnComboBox->addItem(tr("3"));
    30. filterColumnLabel = new QLabel(tr("Filter column: "));
    31.  
    32. connect (filterPatternLineEdit, SIGNAL(textChanged(QString)),this,SLOT(filterREChanged()));
    33. connect (filterColumnComboBox, SIGNAL(currentIndexChanged(int)),this,SLOT(filterColumnChanged()));
    34.  
    35. proxyLayout = new QGridLayout;
    36. proxyLayout->addWidget(proxyView, 0, 0, 1, 3);
    37. proxyLayout->addWidget(filterPatternLabel, 1, 0);
    38. proxyLayout->addWidget(filterPatternLineEdit, 1, 1, 1, 2);
    39. proxyLayout->addWidget(filterColumnLabel, 2, 0);
    40. proxyLayout->addWidget(filterColumnComboBox, 2, 1, 1, 2);
    41. setLayout(proxyLayout);
    42.  
    43. proxyView->sortByColumn(1,Qt::AscendingOrder);
    44. filterColumnComboBox->setCurrentIndex(1);
    45. }
    46. void EGlowny::pasekmenu()
    47. {
    48. QMenu *Plik = menuBar()->addMenu(tr("Baza"));
    49. QAction *action = Plik->addAction(tr("..."));
    50. }
    To copy to clipboard, switch view to plain text mode 

    baz.h - from this file comes extern functions

    Qt Code:
    1. {
    2. QStandardItemModel *model = new QStandardItemModel(0, 3, parent);
    3. model->setHeaderData(0, Qt::Horizontal, QObject::tr("Subject"));
    4. model->setHeaderData(1, Qt::Horizontal, QObject::tr("Sender"));
    5. model->setHeaderData(2, Qt::Horizontal, QObject::tr("Date"));
    6. dodajwpis(model, "as", "qb", "sac","wd");
    7. dodajwpis(model, "aa", "bs", "sc","asd");
    8. dodajwpis(model, "xw", "yx", "sz","saa");
    9. return model;
    10. }
    11.  
    12. void dodajwpis(QAbstractItemModel *model, QString wpistyp, QString wpisnazwa, QString wpiszaw, QString wpiskraj)
    13. {
    14. model->insertRow(0);
    15. model->setData(model->index(0,0),wpistyp);
    16. model->setData(model->index(0,1),wpisnazwa);
    17. model->setData(model->index(0,2),wpiszaw);
    18. model->setData(model->index(0,3),wpiskraj);
    19. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2012
    Location
    Montreal
    Posts
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Attempting to set QLayout on ..., which already has layout

    EGlowny derives from QMainWindow which already has a layout with a center widget, a dockable toolbar and menubar. The code you provided didn't compile, but what you need to do is to set up your layout on the centralWidget() instead of the main window. You could also derive EGlowny from a QWidget instead of a QMainWindow if you don't need the facilities of the QMainWindow.

  3. The following user says thank you to maximebd for this useful post:

    Pawello (18th August 2012)

  4. #3
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default Re: Attempting to set QLayout on ..., which already has layout

    Thank you. Problem solved

Similar Threads

  1. Replies: 8
    Last Post: 29th April 2024, 12:22
  2. Replies: 6
    Last Post: 13th August 2011, 18:31
  3. Replies: 6
    Last Post: 3rd December 2010, 00:07
  4. Using QLayout for layout in a graphics scene
    By ticica in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2009, 04:07
  5. Replies: 4
    Last Post: 5th September 2009, 15:24

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
  •  
Qt is a trademark of The Qt Company.