Results 1 to 6 of 6

Thread: why does QTableView expand to cover the buttons

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default why does QTableView expand to cover the buttons

    I did this program outside Eclipse(with built in Qt4)

    and inside Eclipse.

    Outside Eclipse, the table view is its own "dialog" OK!
    Scroll bars show up perfectly!

    Inside Eclipse the tableview shares a dialog with two buttons:
    (1) show table(from MySQL database)
    (2) close

    When I hit the button "show table" the table shows in the table view but covers the two buttons.
    Using grid layout, the buttons are on top of the table view.
    Scroll bars work! I tried vertical and horizontal layout even with spacers!

    I inserted the table view into a frame and the problem is solved except that there are no scrollbars!

    I did try using the qt designer OUTSIDE Eclipse!

    Why does the table view flood the dialog?

    Qt Code:
    1. // querymodel.h
    2.  
    3. #ifndef QUERYMODEL_H
    4. #define QUERYMODEL_H
    5.  
    6. #include <QMessageBox>
    7. #include <QSqlDatabase>
    8. #include <QSqlError>
    9. #include <QSqlQuery>
    10. #include <QSqlQueryModel>
    11. #include <QSqlTableModel>
    12. #include <QtDebug>
    13.  
    14. #include <QtGui/QWidget>
    15. #include "ui_querymodel.h"
    16.  
    17. class querymodel : public QWidget
    18. {
    19. Q_OBJECT
    20.  
    21. public:
    22. querymodel(QWidget *parent = 0);
    23. ~querymodel();
    24. public slots:
    25. void showTable();
    26. private:
    27. Ui::querymodelClass ui;
    28. };
    29.  
    30. #endif // QUERYMODEL_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // querymodel.cpp
    2. #include "querymodel.h"
    3.  
    4. querymodel::querymodel(QWidget *parent)
    5. : QWidget(parent)
    6. {
    7. ui.setupUi(this);
    8. connect( ui.pushButtonShowTable, SIGNAL(clicked()), this, SLOT(showTable()) );
    9. }
    10.  
    11. querymodel::~querymodel()
    12. {
    13. delete model;
    14.  
    15. }
    16. void querymodel::showTable()
    17. {
    18. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    19. db.setHostName("localhost");
    20. db.setDatabaseName("landonx");
    21. db.setUserName("landon4");
    22. db.setPassword("3141");
    23. db.setConnectOptions(QString("CLIENT_INTERACTIVE"));
    24. bool ok = db.open();
    25. model = new QSqlTableModel();
    26. model->setTable( "log_book" );
    27. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    28.  
    29. model->select();
    30. model->setHeaderData( 0, Qt::Horizontal, QObject::tr("rowid") );
    31. model->setHeaderData( 1, Qt::Horizontal, QObject::tr("fdate") );
    32. model->setHeaderData( 2, Qt::Horizontal, QObject::tr("acid") );
    33. model->setHeaderData( 3, Qt::Horizontal, QObject::tr("actype") );
    34. model->setHeaderData( 4, Qt::Horizontal, QObject::tr("nlandings") );
    35. model->setHeaderData( 5, Qt::Horizontal, QObject::tr("nhours") );
    36. // QTableView *view = new QTableView();
    37. ui.tableView->setModel( model );
    38. ui.tableView->setAlternatingRowColors ( true );
    39. ui.tableView->setFixedSize ( 800,500 );
    40. ui.tableView->show();
    41.  
    42.  
    43. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by landonmkelsey; 5th September 2008 at 12:20. Reason: change in sentence

Similar Threads

  1. Replies: 1
    Last Post: 16th May 2008, 20:31

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.