Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: QTableWidget Not expanding to size of QDockWidget

  1. #1
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default QTableWidget Not expanding to size of QDockWidget

    Hello all,

    I am running into an issue with a QTableWidget not expanding to the size of the QDockWidget it is being created inside of. I am not specifying a layout. I have tried implementing minimumSizeHint() and sizeHint() in the QTableWidget derived class. It is called once upon startup but never again when I insert columns in my table. I have tried calling it explicitly after a column insertion but it doesn't make a difference in the size. I tried force executing updateGeometry() as well, again to no avail.

    This first picture shows what it looks like when my app loads. As you see the table in the "Output" is not expanded to the extent of the QDockWidget.
    output1.jpg

    This one shows what happens when I insert a column.
    output2.jpg

    How do I get this to work as I want it to?

    Cheers!
    -Caolan.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    Is the table widget the one you set with QDockWidget::setTableWidget?

    Cheers,
    _

  3. #3
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    Yes it is. And it's a QTableView, not widget...

    Qt Code:
    1. pDock = new QDockWidget(tr("Output"), this);
    2. m_pPhysEqSolver = new PhysEqSolver(1, 2, pDock);
    3. pDock -> setWidget(m_pPhysEqSolver);
    4. pDock -> setAllowedAreas(Qt::BottomDockWidgetArea);
    5. addDockWidget(Qt::BottomDockWidgetArea, pDock);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class PhysEqSolver : public QTableView {
    2. Q_OBJECT
    3. public:
    4. PhysEqSolver(int rows = 0, int cols = 1, QWidget * = NULL);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    Hmm, ok.

    Try setting the size policy of PhysEqSolver to Expanding in both directions.

    Cheers,
    _

  5. #5
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    I set the QTableWidget in the QTableView to use this: setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); I also tried Maximum in both height and width parameters and no change.


    Added after 17 minutes:


    Now here's something interesting, I hardcoded the size:

    Qt Code:
    1. QSize size(640,480);
    2. setMinimumSize(size);
    3. setMaximumSize(size);
    To copy to clipboard, switch view to plain text mode 

    And it ended up looking like this. Please note that the scroll bad nolonger appears when I insert beyond the viewable area however if I undock the window and expand it beyond the 640x480 area I see the scrollbar, as I would expect it to.

    So I guess the trick here then is ensuring that the size of the window is set to the area of the docked space.
    output3.jpg


    Added after 51 minutes:


    ANyway, still not resolved as I want it to match the window size as I resize it, dock, undock, then dock again.
    Last edited by Caolan O'Domhnaill; 22nd December 2015 at 07:32.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    Quote Originally Posted by Caolan O'Domhnaill View Post
    I set the QTableWidget in the QTableView to use this: setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); I also tried Maximum in both height and width parameters and no change.
    size policy Maximum means that the size returned by the widget's sizeHint() method is the maximum size for the widget.
    So the opposite of what you want.

    Have you tried putting you view into a widget with a layout and setting that on the dock widget?
    E.g. a QFrame so that you can see if the view doesn't resize or the frame doesn't.

    Cheers,
    _

  7. #7
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    I have given the QDockWidget a layout but it didn't work. So what you're saying then is to embed a generic QFrame inside of the QDockWidget, set a layout, then embed my QTableView inside of that? Sure that sounds daft but I'll give it a try.

  8. #8
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    I tried a few different things and couldn't get it to work. Would you mind pointing me to an example of what you're speaking of for me to test and play around with?

  9. #9
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    Is there an example that points me to what you are suggesting I do? I am at a loss here.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    I can't really reproduce your problem.

    A simple table view in a dock widget is always as big as the dock widget, using scrollbars when necessary.
    tableindockwidget.zip

    Cheers,
    _

  11. #11
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    Thank you!

    I have reviewed the code and it seems that the only thing I am doing differently is that I am not using a model associated with the table. Does the model handle correct drawing of the window?

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    The model is not involved in drawing, though it can provide drawing specific data such as font, color, etc.
    My model doesn't do any of those though.

    When you write "not using a model", how does your view get its data?

    Cheers,
    _

  13. #13
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    I access the generic model from within the view as shown below. The examples I have used to get me going did not utilise the model/view architecture and since this worked as well, I kept it up as it did not prevent me from doing what I needed to.

    Qt Code:
    1. void PhysEqSolverTable::insertColumn() {
    2.  
    3. // When inserting a new column with the default value, it should be added to the previous column
    4. int idx = m_TimeSliceValues.count() - 1;
    5. double newValue = m_TimeSliceValues.at(idx) + 1.0;
    6. m_TimeSliceValues.push_back(newValue);
    7. m_pHeader ->timeSliceList(m_TimeSliceValues);
    8. model() ->insertColumn(model() ->columnCount());
    9. rebuildColumnHeaders();
    10. }
    11.  
    12. void PhysEqSolverTable::removeColumn(const int idx) {
    13. if (model() ->columnCount() > 2) {
    14. model() ->removeColumn(idx);
    15. m_TimeSliceValues.removeAt(idx);
    16. m_pHeader ->timeSliceList(m_TimeSliceValues);
    17. rebuildColumnHeaders();
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Caolan O'Domhnaill; 29th December 2015 at 03:46.

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    A QTableView doesn't have any default model.
    Is this a QTableWidget?

    Cheers,
    _

  15. #15
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    The table itself yes. The View that houses it is derived from QTableView.

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    If you don't set a model, then the model is this:
    http://code.woboq.org/qt5/qtbase/src...EmptyItemModel

    Cheers,
    _

  17. #17
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    It seems though that I am able to work perfectly fine without using a model in conjunction with my views. Is there a compelling reason to use a model other than separatinjg data from the UI elements? I hve read the documentation on it and although I can see the benefits, and I have a plan to do the separation later after initial release, there doesn't seem to be much that is preventing me from keeping along the path I am going with this...

    BTW, in relation to the original thread I have the QDockWidget containing my QTableView which contains a QTableWidget. Do you think this has anything to do with the drawing issues I am encountering?

  18. #18
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    Quote Originally Posted by Caolan O'Domhnaill View Post
    It seems though that I am able to work perfectly fine without using a model in conjunction with my views. Is there a compelling reason to use a model other than separatinjg data from the UI elements?
    Well, if you want the views to do anything, then they need data to work on.
    You either provide the data via a model, i.e. either one of the standard models or a custom model, or you use the item widgets with their built-in models.

    Quote Originally Posted by Caolan O'Domhnaill View Post
    BTW, in relation to the original thread I have the QDockWidget containing my QTableView which contains a QTableWidget. Do you think this has anything to do with the drawing issues I am encountering?
    QTableView is usually not a container widget, so what do you mean with "it contains a QTableWidget"?

    Cheers,
    _

  19. #19
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QTableWidget Not expanding to size of QDockWidget

    Quote Originally Posted by anda_skoa View Post
    Well, if you want the views to do anything, then they need data to work on.
    You either provide the data via a model, i.e. either one of the standard models or a custom model, or you use the item widgets with their built-in models.
    _
    For example I have in the subclassed View class my data which is at the bottom of the class definition.

    Qt Code:
    1. class PhysEqSolver : public QTableView, public PhysCommon {
    2. Q_OBJECT
    3. public:
    4. PhysEqSolver(int rows = 0, int cols = 1, QWidget * = NULL);
    5.  
    6. void CartesianDataObj(CartesianGraphDataObj *pObj) { m_pTable -> CartesianDataObj(pObj); }
    7. QList<PhysParticle *> Particles() const { return m_pTable -> CartesianDataObj() ->Particles(); }
    8. QList<PhysVector *> Vectors() const { return m_pTable -> CartesianDataObj() ->Vectors(); }
    9.  
    10. PhysEqSolverTable *Table() const { return m_pTable; }
    11.  
    12. private:
    13. void createParticleItems(int, PhysParticle *);
    14. void create1DKinematicItems(int, PhysParticle *);
    15. QTableWidgetItem *createRowItem(PhysDataObj *);
    16. QTableWidgetItem *createTableItem(PhysDataObj *, bool = false);
    17.  
    18. void createConnections();
    19. void createTable(const int, const int);
    20. void setupTableLookAndFeel();
    21. void createGrid();
    22. void setupContextMenu();
    23.  
    24. QStringList findVariablesInGrid(PhysEqRow *);
    25. QList<double> findValuesOfVariablesInGrid(PhysEqRow *);
    26.  
    27. void DecodeAddy(const QString, int *, int * = NULL);
    28. QString EncodeAddy(const int, const int = -1);
    29. void createTimeSliceRow(QList<double>);
    30. void addPhysDataObjCell(const int row, const int col, const QString, const double val);
    31.  
    32. void createPhysDataObjRow(PhysDataObj *);
    33. public slots:
    34. void updateLineEdit(QTableWidgetItem *);
    35. void returnPressed();
    36. void onAddPhysEqSolverRow(QList<PhysParticle *>);
    37. void onCalculate();
    38. void onUpdateParticleName(const QString, const QString);
    39. void onAddTimeSliceCell(int, double);
    40. void onRemoveTimeSliceCell(int);
    41. void onCartesianGraphCreated(CartesianGraphDataObj *pObj) { m_pTable ->CartesianDataObj(pObj); }
    42. void onSetModType(int modType) {}
    43. signals:
    44. private:
    45. PhysEqSolverTable *m_pTable;
    46. QLineEdit *m_pFormulaInput;
    47. QList<PhysEqRow *> m_lstRows;
    48. PhysEqGrid *m_pGrid;
    49. QList<PhysParticle *> m_lstParticles;
    50. PhysCalculateTimer *m_pCalcTimer;
    51. };
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by anda_skoa View Post
    QTableView is usually not a container widget, so what do you mean with "it contains a QTableWidget"?

    Cheers,
    _
    In the code above you can see this line:
    Qt Code:
    1. PhysEqSolverTable *m_pTable;
    To copy to clipboard, switch view to plain text mode 

    Which is a derived QTableWidget. My View class contains this widget.

  20. #20
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Not expanding to size of QDockWidget

    That looks weird.

    What do you need the table view for?
    It looks like your table is the table widget.

    Cheers,
    _

Similar Threads

  1. Layout Expanding Font Size
    By Henry Blue Heeler in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2015, 06:55
  2. Replies: 2
    Last Post: 3rd January 2015, 05:48
  3. Dealing with Layout expanding size
    By edxxgardo in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2011, 10:20
  4. Replies: 1
    Last Post: 20th May 2011, 17:36
  5. Expanding QToolButton size
    By kodiak in forum Qt Programming
    Replies: 2
    Last Post: 4th June 2009, 07:17

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.