Results 1 to 3 of 3

Thread: qt design and adding other code

  1. #1
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default

    i use the QT Designer and create a simple UI file inhertied from QMainwindow,in its Construct function,I add a treewidget and textedit component, but how to layout them?
    I Add a QVboxlayout, but it did not work.
    Following is my code :

    Qt Code:
    1. frmMainWindow::frmMainWindow()
    2. {
    3. setupUi(this);
    4. connect(radioButton,SIGNAL(toggled(bool)),this,SLOT(oncheckBoxclick(bool)));
    5.  
    6. QVBoxLayout *vboxlayout=new QVBoxLayout();
    7.  
    8. QTreeWidget *treeWidget = new QTreeWidget(this);
    9. //treeWidget->setGeometry(QRect(0,0,200,100));
    10. treeWidget->setColumnCount(1);
    11. QList<QTreeWidgetItem *> items;
    12. for (int i = 0; i < 100; ++i)
    13. items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
    14. treeWidget->insertTopLevelItems(0, items);
    15. treeWidget->setSizeIncrement(10,50);
    16. treeWidget->setMinimumSize(100,500) ;
    17. treeWidget->setLayout(vboxlayout);
    18.  
    19. QTextEdit *edit=new QTextEdit(this);
    20. edit->insertPlainText("11111111111111111111111111111111111111111111111111");
    21. edit->insertPlainText("22222222222222222222222222222222222222222222222222");
    22. edit->setMinimumSize(100,100);
    23. edit->setLayout(vboxlayout);
    24.  
    25. vboxlayout->addSpacing(6);
    26. //vboxlayout->addWidget(treeWidget);
    27. //vboxlayout->addWidget(edit);
    28. vboxlayout->addStretch(100) ;
    29.  
    30. setLayout(vboxlayout);
    31. }
    To copy to clipboard, switch view to plain text mode 

    other more, when I put the QTreewidget in QMainwindow directly in the QT Designer ,not create in Constructor using code,then uic the ui file and moc the file ,but when i run ,I can not focus all the widget ,even the form. it just like in dead loop and can not response to any event !


    i save the ui to test.ui, then uic to get the test.h .
    create cfrmmain.h from test.h, then moc the cfrmmain to get moc_cfrmmain.h,
    implement the cfrmmain.h in cfrmmain.cpp.

    Qt Code:
    1. /////// cfrmmain.h ////////
    2. #include "test.h"
    3. class frmMainWindow:public QMainWindow,public Ui::frmMainwindow
    4. {
    5. Q_OBJECT
    6. public:
    7. frmMainWindow();
    8. //private slots:
    9. // void oncheckBoxclick(bool);
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /////////cfrmmain.cpp/////
    2. #include "cfrmmain.h"
    3. frmMainWindow::frmMainWindow()
    4. {
    5. setupUi(this);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ////////main.cpp///////////
    2. #include <QApplication>
    3. #include "cfrmmain.h"
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. frmMainWindow * mainwindow=new frmMainWindow;
    8. mainwindow->show();
    9.  
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 1st February 2007 at 17:10. Reason: Merged two posts and fixed missing tags

  2. #2
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: qt design and adding other code

    Second question i have found a solution . Must give a layout for the mainwindow,now it can get the event.but how to arrange the manual widget ,maybe you can have good advice.

  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: qt design and adding other code

    Qt Code:
    1. treeWidget->setLayout(vboxlayout);
    2. edit->setLayout(vboxlayout);
    3. setLayout(vboxlayout);
    To copy to clipboard, switch view to plain text mode 
    Didn't you by any chance mean the following?
    Qt Code:
    1. vboxlayout->addWidget(treeWidget);
    2. vboxlayout->addWidget(edit);
    3. setLayout(vboxlayout);
    To copy to clipboard, switch view to plain text mode 

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.