Jak mowilem na pewno problemy wystapia i juz mam jeden ;). Chce sobie stworzyc etykiety ktore beda aktualizowane co ruch gracza i wyswietlane. Samo to wiem jak zrobic, jednak po podlaczeniu do slota funkcji wyswietlajacej nie rysuje ona nic.
mainwindow.h
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <QApplication>
#include <QMainwindow>
#include <QTextCodec>
#include <QPushButton>
#include <QLabel>
#include <QMenuBar>
#include <QStatusBar>
#include <QGridLayout>
#include "gra.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
private:
QPushButton *ruch,*kup,*sprzedaj;
QLabel *poleGry;
QLabel *pionek0,*pionek1,*pionek2,*pionek3;
vector<QLabel*>konta;
QMenu *menu;
QMenu *setPlayer;
QAction *player2;
QAction *player3;
QAction *player4;
QAction *quitAction;
gra *plansza;
void createMenus();
void movePlayer(int nr, int poz);
void moveP2(int nr, int cel);
int g0,g1,g2,g3; //tymczasowe pol graczy
int ktory; //zapamietujemy czyja kolej
int ile_graczy; //do wczytania
public:
MainWindow();
private slots:
void SetPlayerCount(short int number);
void foo();
};
#endif // MAINWINDOW_HPP
mainwindow.cpp
#include "mainwindow.h"
int tabx[40]={487,416,377,338,299,260,223,184,145,106,34,34,34,34,34,34,34,34,34,34,34,106,145,184,223,260,299,338,377,416,487,487,487,487,487,487,487,487,487,487};
int taby[40]={547,547,547,547,547,547,547,547,547,547,547,476,437,398,360,321,282,244,205,166,93,93,93,93,93,93,93,93,93,93,93,166,205,244,282,321,360,398,437,476};
MainWindow::MainWindow()
{
createMenus();
setMinimumSize(520,580);
setMaximumSize(520,580);
ruch = new QPushButton(tr("&Ruch"),this);
ruch->setGeometry(10,30,100,30);
ruch->connect(ruch,SIGNAL(clicked()),this,SLOT(foo()));
kup = new QPushButton(tr("&Kup"),this);
kup->setGeometry(120,30,100,30);
kup->hide(); //jak nizej
sprzedaj = new QPushButton(tr("&Sprzedaj"),this);
sprzedaj->setGeometry(230,30,100,30);
sprzedaj->hide(); //pokazuje sie tylko gdy mozliwy zakup
QPixmap pixmap1("F:\\Dropbox\\FlorasShared\\eurobiznes\\obrazki\\plansza.png");
poleGry = new QLabel(0,this);
poleGry->setGeometry(10,70,500,500);
poleGry->setPixmap(pixmap1.scaled(500,500));
pionek0 = new QLabel(0,this);
pionek0->setGeometry(487,547,15,15);
QPixmap pionekpix0("F:\\Dropbox\\FlorasShared\\eurobiznes\\obrazki\\czerwony.png");
pionek0->setPixmap(pionekpix0.scaled(15,15));
pionek1 = new QLabel(0,this);
pionek1->setGeometry(487,530,15,15);
QPixmap pionekpix1("F:\\Dropbox\\FlorasShared\\eurobiznes\\obrazki\\niebieski.png");
pionek1->setPixmap(pionekpix1.scaled(15,15));
pionek2 = new QLabel(0,this);
pionek2->setGeometry(470,547,15,15);
QPixmap pionekpix2("F:\\Dropbox\\FlorasShared\\eurobiznes\\obrazki\\zielony.png");
pionek2->setPixmap(pionekpix2.scaled(15,15));
pionek3 = new QLabel(0,this);
pionek3->setGeometry(470,530,15,15);
QPixmap pionekpix3("F:\\Dropbox\\FlorasShared\\eurobiznes\\obrazki\\rozowy.png");
pionek3->setPixmap(pionekpix3.scaled(15,15));
g1=g0=g2=g3=0;
ktory=0;
}
void MainWindow::foo()
{
int los=rand()%6+1;
movePlayer(ktory,los);
ktory++;
if(ktory==4)ktory=0;
}
void MainWindow::createMenus()
{
menu = menuBar()->addMenu(tr("&Menu"));
setPlayer = menu->addMenu(tr("&Ilosc graczy"));
player2 = new QAction(tr("&2 Graczy"),this);
player3 = new QAction(tr("&3 Graczy"),this);
player4 = new QAction(tr("&4 Graczy"),this);
quitAction = new QAction(tr("&Wyjscie"), this);
quitAction->setStatusTip(tr("Wyjdz z programu"));
connect (quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
setPlayer->addAction(player2);
connect (player2, SIGNAL(triggered()), this, SLOT(SetPlayerCount(2)));
setPlayer->addAction(player3);
setPlayer->addAction(player4);
menu->addAction(quitAction);
}
void MainWindow::SetPlayerCount(short int number)
{
int x=0;
switch(number)
{
case 2:
konta.resize(2);
plansza = new gra(2);
for(int i=0;i<2;i++)
{
konta[i]->setText("aaaaaaaaaaaa");
konta[i]->setGeometry(x+15,15,100,30);
x+=50;
}
}
}
Chcialem polaczyc w menu przycisk 2 graczy z funkcja setplayercount ktora ustawi ilosc graczy i narysuje odpowiednie etykiety. Jednak nic nie rysuje. na razie tylko dla 2, bo nie dziala i tak.