#include "test.h"
#include "ui_test.h"
#include "PlayerWidget.h"
#include <QGraphicsProxyWidget>
ui(new Ui::test),
m_pokerScene{ nullptr },
m_deck{ new Deck() }, //TODO: memory leak???
m_pot{ 0 },
m_flopCard1Pos
{ QPointF(430,
350) },
m_flopCard2Pos
{ QPointF(560,
350) },
m_flopCard3Pos
{ QPointF(690,
350) },
m_turnCardPos
{ QPointF(820,
350) },
m_riverCardPos
{ QPointF(950,
350) },
m_tableName{ "" },
m_maxPlayers{ 9 },
m_buyInChipAmount{ 2000 },
m_timeToAct{ 20000 }, // in milliseconds
m_smallBlind{ 25 },
m_bigBlind{ 50 }
{
ui->setupUi(this);
// Set up my QGraphicsScene of a poker table
// and add items to it below
m_pokerScene->addItem(m_backgroundImage);
for (auto& card : m_deck->getDeck())
{
m_pokerScene->addItem(&card);
card.setPos(m_deckPos);
}
PlayerWidget* player1 = new PlayerWidget;
QGraphicsProxyWidget *player1Proxy = m_pokerScene->addWidget(player1);
player1Proxy->setPos(0,0);
m_deck->getDeck()[0].setPos(m_flopCard1Pos);
m_deck->getDeck()[1].setPos(m_flopCard2Pos);
m_deck->getDeck()[2].setPos(m_flopCard3Pos);
m_deck->getDeck()[3].setPos(m_turnCardPos);
m_deck->getDeck()[4].setPos(m_riverCardPos);
// tableArea is my QGraphicsView, embedded in this QWidget,
// and is part of a Vertical Layout (see photo)
ui->tableArea->setScene(m_pokerScene);
ui->tableArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff );
// This call is where the problem seems to be,
// below it are a few different ways I've tried so far
// If I comment it out, the graphic appears zoomed in
// by what looks like 50%, and I can scroll around to the normal edges
ui->tableArea->fitInView( m_pokerScene->sceneRect(), Qt::KeepAspectRatio );
// This one looks the closest to correct, but I don't know why! Still not right
// ui->tableArea->fitInView( QRectF(0, 0, 1, 51), Qt::KeepAspectRatio );
// This one makes the graphic a little larger than the active, non-commented out call
// ui->tableArea->fitInView( QRectF(0, 0, 900, 400), Qt::KeepAspectRatio );
// This one also shows the graphic zoomed in by what looks like 50%, and I can scroll
// ui->tableArea->fitInView( QRectF(0, 0, 0, 0), Qt::KeepAspectRatio );
// This one has same result as the active, non-commented out call
// ui->tableArea->fitInView( m_backgroundImage, Qt::KeepAspectRatio );
// These last seven lines are here to show the same QGraphicsScene
// in a new QGraphicsView that's unrelated to my poker widget
// and works like I expect and want it to (see attached photos)
testView->setScene(m_pokerScene);
testView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
testView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff );
testView->fitInView( m_pokerScene->sceneRect(), Qt::KeepAspectRatio );
testView->setWindowTitle("How It Should Look When Part Of My QWidget");
testView->show();
}
#include "test.h"
#include "ui_test.h"
#include "PlayerWidget.h"
#include <QGraphicsProxyWidget>
test::test(QWidget *parent) :
QWidget(parent),
ui(new Ui::test),
m_pokerScene{ nullptr },
m_backgroundImage { new QGraphicsPixmapItem( QPixmap(":/resources/images/GreenTabletop 1920x1080.png")) },
m_deck{ new Deck() }, //TODO: memory leak???
m_pot{ 0 },
m_deckPos{ QPointF(690, 150) },
m_flopCard1Pos{ QPointF(430, 350) },
m_flopCard2Pos{ QPointF(560, 350) },
m_flopCard3Pos{ QPointF(690, 350) },
m_turnCardPos{ QPointF(820, 350) },
m_riverCardPos{ QPointF(950, 350) },
m_tableName{ "" },
m_maxPlayers{ 9 },
m_buyInChipAmount{ 2000 },
m_timeToAct{ 20000 }, // in milliseconds
m_smallBlind{ 25 },
m_bigBlind{ 50 }
{
ui->setupUi(this);
// Set up my QGraphicsScene of a poker table
// and add items to it below
m_pokerScene = new QGraphicsScene();
m_pokerScene->addItem(m_backgroundImage);
for (auto& card : m_deck->getDeck())
{
m_pokerScene->addItem(&card);
card.setPos(m_deckPos);
}
PlayerWidget* player1 = new PlayerWidget;
QGraphicsProxyWidget *player1Proxy = m_pokerScene->addWidget(player1);
player1Proxy->setPos(0,0);
m_deck->getDeck()[0].setPos(m_flopCard1Pos);
m_deck->getDeck()[1].setPos(m_flopCard2Pos);
m_deck->getDeck()[2].setPos(m_flopCard3Pos);
m_deck->getDeck()[3].setPos(m_turnCardPos);
m_deck->getDeck()[4].setPos(m_riverCardPos);
// tableArea is my QGraphicsView, embedded in this QWidget,
// and is part of a Vertical Layout (see photo)
ui->tableArea->setScene(m_pokerScene);
ui->tableArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff );
// This call is where the problem seems to be,
// below it are a few different ways I've tried so far
// If I comment it out, the graphic appears zoomed in
// by what looks like 50%, and I can scroll around to the normal edges
ui->tableArea->fitInView( m_pokerScene->sceneRect(), Qt::KeepAspectRatio );
// This one looks the closest to correct, but I don't know why! Still not right
// ui->tableArea->fitInView( QRectF(0, 0, 1, 51), Qt::KeepAspectRatio );
// This one makes the graphic a little larger than the active, non-commented out call
// ui->tableArea->fitInView( QRectF(0, 0, 900, 400), Qt::KeepAspectRatio );
// This one also shows the graphic zoomed in by what looks like 50%, and I can scroll
// ui->tableArea->fitInView( QRectF(0, 0, 0, 0), Qt::KeepAspectRatio );
// This one has same result as the active, non-commented out call
// ui->tableArea->fitInView( m_backgroundImage, Qt::KeepAspectRatio );
// These last seven lines are here to show the same QGraphicsScene
// in a new QGraphicsView that's unrelated to my poker widget
// and works like I expect and want it to (see attached photos)
QGraphicsView* testView = new QGraphicsView;
testView->setScene(m_pokerScene);
testView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
testView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff );
testView->fitInView( m_pokerScene->sceneRect(), Qt::KeepAspectRatio );
testView->setWindowTitle("How It Should Look When Part Of My QWidget");
testView->show();
}
To copy to clipboard, switch view to plain text mode
Bookmarks