So after some playing around it appears it doesn't work as it should.
I have:
main.cpp
#include <QGroupBox>
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <MyTable.h>
int main(int argc, char *argv[])
{
{
sublay->addWidget( new MyTable(box));
box->setLayout(sublay);
layout->addWidget(box);
}
{ /* same as above */
sublay->addWidget( new MyTable(box));
box->setLayout(sublay);
layout->addWidget(box);
}
{ /* same as above */
sublay->addWidget( new MyTable(box));
box->setLayout(sublay);
layout->addWidget(box);
}
window->setLayout(layout);
window->show();
return app.exec();
}
#include <QGroupBox>
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <MyTable.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget();
QVBoxLayout *layout = new QVBoxLayout();
{
QGroupBox * box = new QGroupBox(window);
QHBoxLayout * sublay = new QHBoxLayout();
sublay->addWidget( new MyTable(box));
box->setLayout(sublay);
layout->addWidget(box);
}
{ /* same as above */
QGroupBox * box = new QGroupBox(window);
QHBoxLayout * sublay = new QHBoxLayout();
sublay->addWidget( new MyTable(box));
box->setLayout(sublay);
layout->addWidget(box);
}
{ /* same as above */
QGroupBox * box = new QGroupBox(window);
QHBoxLayout * sublay = new QHBoxLayout();
sublay->addWidget( new MyTable(box));
box->setLayout(sublay);
layout->addWidget(box);
}
window->setLayout(layout);
window->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
MyTable.h
#include <QTableWidget>
#include <QFocusEvent>
#include <QEvent>
#include <QLineEdit>
#include <iostream>
{
Q_OBJECT
public:
{
setColumnCount(7);
setRowCount(1);
for(unsigned int i = 0; i < columnCount(); ++i)
{
}
}
bool focusNextPrevChild( bool next )
{
}
};
#include <QTableWidget>
#include <QFocusEvent>
#include <QEvent>
#include <QLineEdit>
#include <iostream>
class MyTable : public QTableWidget
{
Q_OBJECT
public:
MyTable( QWidget * parent = 0) : QTableWidget(parent)
{
setColumnCount(7);
setRowCount(1);
for(unsigned int i = 0; i < columnCount(); ++i)
{
setCellWidget(0, i, new QLineEdit(this));
}
}
bool focusNextPrevChild( bool next )
{
QWidget::focusNextPrevChild(next);
}
};
To copy to clipboard, switch view to plain text mode
The code above is compilable.
To compile:
moc MyTable.h -o MyTable.cpp
g++ MyTable.cpp main.cpp `pkg-config QtGui --cflags --libs` -I . -o table
moc MyTable.h -o MyTable.cpp
g++ MyTable.cpp main.cpp `pkg-config QtGui --cflags --libs` -I . -o table
To copy to clipboard, switch view to plain text mode
First question: shouldn't this work like this: when I press tab it goes to the next MyTable widget?
Because I thought that if I call directly QWidget::focusNextPrevChild(bool) it will treat MyTable as any other QWidget which can have focus, so it should navigate through all three MyTables not going into cells.
Bookmarks