Results 1 to 3 of 3

Thread: Resize TableView to that of parent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Resize TableView to that of parent

    Hi Everyone, I recently got started with Qt and I'm having an issue with my layout management. In the following code I'd like to have the tableView resize to that of the parent widget. Do I have to put the layout in a QMainWindow or is there some method I can call on QTableView. thanks so much.

    Qt Code:
    1. #include "acme.h"
    2. #include "dataModel.h"
    3.  
    4. Ramble::Ramble(){
    5.  
    6. //create our ui
    7. QWidget parent;
    8.  
    9. QVBoxLayout* main_window = new QVBoxLayout(&parent);
    10. QHBoxLayout* top_pane = new QHBoxLayout;
    11. QVBoxLayout* bottom_pane = new QVBoxLayout;
    12.  
    13. QListView* tags = new QListView;
    14. QTextEdit* context_view = new QTextEdit;
    15. QTableView* library = new QTableView;
    16.  
    17. //pack top and bottom pane
    18. top_pane->addWidget(tags);
    19. top_pane->addWidget(context_view);
    20. bottom_pane->addWidget(library);
    21.  
    22. //create and populate our database
    23. dataModel* music_data_model = new dataModel(this);
    24. QSqlTableModel* table_model = music_data_model->getDummyData();
    25. library->setModel(table_model);
    26.  
    27. //set up our layout
    28. main_window->addLayout(top_pane);
    29. main_window->addLayout(bottom_pane);
    30. setLayout(main_window);
    31. }
    32.  
    33. Ramble::~Ramble(){}
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Resize TableView to that of parent

    Whats with QListView and QTextEdit? Remove them (don't add them) then QTreeView will take up the complete area (with margin) in parent widget.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Aug 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Resize TableView to that of parent

    Quote Originally Posted by Santosh Reddy View Post
    Whats with QListView and QTextEdit? Remove them (don't add them) then QTreeView will take up the complete area (with margin) in parent widget.
    Hi Santosh, sorry for the late reply as I didn't get an email notification about this thread.
    Okay, so the ListView and the TextEdit widget are both widgets I need in my application. so the question still stands, is there a way to have the tableview exapand to that of the parent's width?

    thanks,


    also where is my code? I posted it but I don't see it on the forum??

Similar Threads

  1. How to resize parent widget when child widget is resized
    By ainne810329 in forum Qt Programming
    Replies: 4
    Last Post: 29th November 2011, 07:47
  2. Replies: 1
    Last Post: 18th July 2011, 15:24
  3. child widget resize to parent widget
    By bobFromAccounting in forum Newbie
    Replies: 10
    Last Post: 11th February 2011, 02:53
  4. Replies: 5
    Last Post: 21st April 2010, 21:36
  5. Infinite loop - resize parent from child
    By bitChanger in forum Qt Programming
    Replies: 3
    Last Post: 5th May 2006, 13:21

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.