#include<QApplication>
#include<tabuleiro.h>
#include<jogador.h>
#include<QWidget>
int main(int argc, char* argv[]){
QApplication app(argc, argv);
QWidget window;
Tabuleiro t(&window);
Jogador j(&window);
window.show();
return app.exec();
return 0;
}
Classes:
#include<tabuleiro.h>
#include<QPainter>
#include<iostream>
using namespace std;
Tabuleiro::Tabuleiro(QWidget* parent)
: QWidget(parent){
layout = new QVBoxLayout();
gerarTabuleiro(1);
repaint();
setFixedSize(960,560);
setLayout(layout);
show();
}
void Tabuleiro::gerarTabuleiro(int modo){
x=0;
y=0;
w=40;
h=40;
switch(modo){
case 1 :
for(int x = 0; x<14 ; x++){
for(int y = 0 ; y<12 ; y++){
tabuleiro[x][y] ='1';
}
}
for(int x = 0; x<14 ; x++){
for(int y = 12 ; y<24 ; y++){
tabuleiro[x][y] ='0';
}
}
break;
}
}
void Tabuleiro::draw(){
repaint();
}
void Tabuleiro::paintEvent(QPaintEvent *event){
QWidget::paintEvent(event);
QPainter painter(this);
painter.setPen(Qt::gray);
for(int c = 0 ; c<14 ; c++){
for(int l = 0 ; l<24 ; l++){
if(tabuleiro[c][l]=='1'){
painter.setBrush(Qt::black);
}
else{
painter.setBrush(Qt::white);
}
painter.drawRect(x,y,w,h);
x+=40;
}
x=0;
y+=40;
}
y=0;
}
My problem is that I'm not able to capture the keyboard event.