Results 1 to 6 of 6

Thread: why does QTableView expand to cover the buttons

  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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why does QTableView expand to cover the buttons

    The problem is in the .ui file, so the code you have posted is completely irrelevant. Do you have a top-level layout for all container widgets?

  3. #3
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: why does QTableView expand to cover the buttons

    here is querymodel.ui

    2 buttons and a table view

    Qt Code:
    1. <ui version="4.0" >
    2. <class>querymodelClass</class>
    3. <widget class="QWidget" name="querymodelClass" >
    4. <property name="geometry" >
    5. <rect>
    6. <x>0</x>
    7. <y>0</y>
    8. <width>698</width>
    9. <height>561</height>
    10. </rect>
    11. </property>
    12. <property name="maximumSize" >
    13. <size>
    14. <width>16776957</width>
    15. <height>16777215</height>
    16. </size>
    17. </property>
    18. <property name="windowTitle" >
    19. <string>querymodel</string>
    20. </property>
    21. <widget class="QPushButton" name="pushButtonClose" >
    22. <property name="geometry" >
    23. <rect>
    24. <x>10</x>
    25. <y>450</y>
    26. <width>83</width>
    27. <height>30</height>
    28. </rect>
    29. </property>
    30. <property name="text" >
    31. <string>Close</string>
    32. </property>
    33. </widget>
    34. <widget class="QPushButton" name="pushButtonShowTable" >
    35. <property name="geometry" >
    36. <rect>
    37. <x>10</x>
    38. <y>410</y>
    39. <width>83</width>
    40. <height>30</height>
    41. </rect>
    42. </property>
    43. <property name="text" >
    44. <string>Show Table</string>
    45. </property>
    46. </widget>
    47. <widget class="QTableView" name="tableView" >
    48. <property name="geometry" >
    49. <rect>
    50. <x>10</x>
    51. <y>20</y>
    52. <width>271</width>
    53. <height>201</height>
    54. </rect>
    55. </property>
    56. <property name="verticalScrollBarPolicy" >
    57. <enum>Qt::ScrollBarAlwaysOn</enum>
    58. </property>
    59. <property name="horizontalScrollBarPolicy" >
    60. <enum>Qt::ScrollBarAlwaysOn</enum>
    61. </property>
    62. </widget>
    63. </widget>
    64. <layoutdefault spacing="6" margin="11" />
    65. <resources/>
    66. <connections>
    67. <connection>
    68. <sender>pushButtonClose</sender>
    69. <signal>clicked()</signal>
    70. <receiver>querymodelClass</receiver>
    71. <slot>close()</slot>
    72. <hints>
    73. <hint type="sourcelabel" >
    74. <x>391</x>
    75. <y>274</y>
    76. </hint>
    77. <hint type="destinationlabel" >
    78. <x>348</x>
    79. <y>227</y>
    80. </hint>
    81. </hints>
    82. </connection>
    83. </connections>
    84. </ui>
    To copy to clipboard, switch view to plain text mode 
    Last edited by landonmkelsey; 6th September 2008 at 03:35. Reason: clarify small detail

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why does QTableView expand to cover the buttons

    Well, you don't have any layouts in this .ui file. To add a top-level layout you have to click on the form's background and then click on of the "Lay out in ..." buttons.

  5. The following user says thank you to jacek for this useful post:

    landonmkelsey (6th September 2008)

  6. #5
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default

    I did what you requested and selected "layout in a form layout"

    whatever that is!

    now I get the following errors:

    make debug
    make -f Makefile.Debug
    make[1]: Entering directory `/home/landon4/workspace/querymodel'
    g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include/QtSql -I/usr/include/QtSql -I/usr/include -Idebug -I. -o debug/main.o main.cpp
    In file included from querymodel.h:14,
    from main.cpp:31:
    ui_querymodel.h:20:25: error: qformlayout.h: No such file or directory
    In file included from querymodel.h:14,
    from main.cpp:31:
    ui_querymodel.h:25: error: ISO C++ forbids declaration of ‘QFormLayout’ with no type
    ui_querymodel.h:25: error: expected ‘;’ before ‘*’ token
    ui_querymodel.h: In member function ‘void Ui_querymodelClass::setupUi(QWidget*)’:
    ui_querymodel.h:36: error: ‘formLayout’ was not declared in this scope
    ui_querymodel.h:36: error: expected type-specifier before ‘QFormLayout’
    ui_querymodel.h:36: error: expected `;' before ‘QFormLayout’
    make[1]: Leaving directory `/home/landon4/workspace/querymodel'
    make[1]: *** [debug/main.o] Error 1
    make: *** [debug] Error 2
    I went back and this time selected "layout in a grid" right clicking in the background

    as you specified.

    this time the table did not overflow the buttons!

    Previously I had first dragged a "grid layout" from the widgets on the left

    and placed the table view and buttons inside the red rectangle. The buttons lay on

    top the table!

    I wonder what the widgets on the left (same selections as right clicking the form background) are for and how one would use those widgets

    Nevertheless, I don't see how the table would have flowed out of its boundaries

    This is a basic premise of the "widget drag system" of design
    Last edited by wysota; 3rd December 2009 at 10:45.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why does QTableView expand to cover the buttons

    Quote Originally Posted by landonmkelsey View Post
    I wonder what the widgets on the left (same selections as right clicking the form background) are for and how one would use those widgets
    These are for creating nested layouts and you can't create a top-level layout using them.

  8. The following user says thank you to jacek for this useful post:

    landonmkelsey (7th September 2008)

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.