PDA

View Full Version : Editing TableViews in UI Editor



emorgen
28th May 2010, 16:50
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.


ImsiViewerGui::ImsiViewerGui(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ImsiViewerGui)
{
ui->setupUi(this);
setTable();
}

ImsiViewerGui::~ImsiViewerGui()
{
delete ui;
}

void ImsiViewerGui::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}

void ImsiViewerGui::setTable()
{
IdentitySQL *isql = new IdentitySQL(this);

isql->connect("c:\\temp\\Identity.db");
ui->identityTableView = isql->createTableView( "IMSI Grabber ");
}


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

alexisdm
28th May 2010, 18:10
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):

// ui->identityPlaceHolder would be the empty QWidget
QVBoxLayout *layout = new QVBoxLayout(ui->identityPlaceHolder);
layout->addWidget(isql->createTableView( "IMSI Grabber "));

emorgen
28th May 2010, 18:43
alexisdm,

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