Results 1 to 3 of 3

Thread: Editing TableViews in UI Editor

  1. #1
    Join Date
    May 2010
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Editing TableViews in UI Editor

    Hello,

    I am using the QT GUI editor to create a small aplication that displays my SQLITE data. I created a class called IdentitySQL that reads the data and returns a QTableView*. When I use the GUI editor, I dragged a tableview object into my main window and gave it the name identityTableView. I'm trying to set that tableview to the one I generated in my class.

    Qt Code:
    1. ImsiViewerGui::ImsiViewerGui(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::ImsiViewerGui)
    4. {
    5. ui->setupUi(this);
    6. setTable();
    7. }
    8.  
    9. ImsiViewerGui::~ImsiViewerGui()
    10. {
    11. delete ui;
    12. }
    13.  
    14. void ImsiViewerGui::changeEvent(QEvent *e)
    15. {
    16. QMainWindow::changeEvent(e);
    17. switch (e->type()) {
    18. case QEvent::LanguageChange:
    19. ui->retranslateUi(this);
    20. break;
    21. default:
    22. break;
    23. }
    24. }
    25.  
    26. void ImsiViewerGui::setTable()
    27. {
    28. IdentitySQL *isql = new IdentitySQL(this);
    29.  
    30. isql->connect("c:\\temp\\Identity.db");
    31. ui->identityTableView = isql->createTableView( "IMSI Grabber ");
    32. }
    To copy to clipboard, switch view to plain text mode 

    In the above code, I set the ui object equal to the other table view but it will never show it when I start the application. The only way I can get this to work is if I edit the ui_<project name>.h file. Unfortunately, every time I made changes to the ui it regenerates the ui_ file and deletes my changes.

    What is the best way to accomplish what I am trying to do? Is there a simple refresh command that I need to run or is there a better method?

    Thanks in advance!

    Emorgen

  2. #2
    Join Date
    May 2010
    Posts
    24
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Editing TableViews in UI Editor

    You can't just replace the content of the variable ui->identityTableView: you have to remove the other widget from its parent layout and put your new Widget at exactly the same location in that layout.

    But the easiest way would be to put an empty QWidget instead of the QTableView in the GUI editor and to insert the generated QTableView inside (with a layout to fill the QWidget):
    Qt Code:
    1. // ui->identityPlaceHolder would be the empty QWidget
    2. QVBoxLayout *layout = new QVBoxLayout(ui->identityPlaceHolder);
    3. layout->addWidget(isql->createTableView( "IMSI Grabber "));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to alexisdm for this useful post:

    emorgen (1st June 2010)

  4. #3
    Join Date
    May 2010
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Editing TableViews in UI Editor

    alexisdm,

    I followed everything you said and it work perfectly. Thanks a lot for the help!

Similar Threads

  1. Editing a file in Qt4
    By grsandeep85 in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2009, 09:33
  2. XML editing with QDom
    By trulysachin in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2008, 16:39
  3. About Editing QtreeWidget
    By nikhilqt in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2008, 13:51
  4. Replies: 5
    Last Post: 18th July 2006, 22: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.