Creating a keypress signal from application button
-
My setup.h file:
@#include "ui_setup.h"
#include "parent_ui.h"
#include "mytableview.h"class Setup: public Parent_ui {
Q_OBJECTpublic:
Setup(QWidget *parent = 0);
~Setup();
MyTableView myTableViewInstance;private:
Ui::SetupClass ui;
void createActions();private slots:
void up();
void down();
void enter();
void back();};@
My setup.cpp file:
@#include "setup.h"
#include <QListWidget>Setup::Setup(QWidget *parent) :
Parent_ui(parent) {ui.setupUi(this);
Parent_ui::ui.headerLabel->setText("SETUP");myTableViewInstance = new MyTableView();
}Setup::~Setup() {
}
@The error I get when calling "myTableViewInstance = new MyTableView();":
'QWidget' is an inaccessible base of 'MyTableView'
-
That was it, thank you :)
Okay to get back to the subject (Which I slowly turned away from introducing other challenges :) ).
I have made a slot in MyTableView:
@void MyTableView::key_down(){
QTableView::moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier);
}@This is then used in my setup.cpp file:
@void Setup::createActions() {
QObject::connect(ui.buttonTwo, SIGNAL(clicked()), this, SLOT(myTableViewInstance->key_down()));
}@
This has no effect on my QTableWidget though. But I guess it's me and my coding which is faulty again. Can you see from my code snippets what I'm doing wrong?
-
Oh... many points:
- In your sources
@class MyTableView: private QTableView {@
although, in example above you wrote:
@class MyTableView: public QTableView {@- You don't needed MyTableView, you already have QTabletWidget on form
- You don't needed inheritance in this case.
- In setup.cpp
I rewrite some things:
It's for local slot, because MyTableView not needed anymore
@connect(ui.buttonTwo, SIGNAL(clicked()), this, SLOT(down()));@
in slot, as example, you can add any checks and other logic to their:
@void Setup::down() {
Parent_ui::ui.tableWidget->selectRow(Parent_ui::ui.tableWidget->currentRow() + 1);
}@same for up slot:
@void Setup::up() {
Parent_ui::ui.tableWidget->selectRow(Parent_ui::ui.tableWidget->currentRow() -1);}@
- In your sources
-
I just wanted to tell you that my code is now working as intended! - Thanks to you!
I'm very impressed of the willingness to help out on this forum. And the fast response was superb.
I'm almost positive that we will talk again! ;)
Thank you so much for your time!