Label cut off
Unsolved
General and Desktop
-
Hi,
I try to develop a Sudoku game and I want to show in a cell not only the current value, but also possible candidates in the corners of the cell. That is, top-left, top-right, top-center, center-left, center-right, bottom-left, bottom-center, bottom-right.
Additionally, I want to highlight the current value with a bigger font-size.
My problem is, thatQLabel
which represents the current value, is cut-off:
In this mockup, the value "C" is cut-off.Each line is represented by a
QHBoxLayout
and all lines are wrapped up withQVBoxLayout
. The cells are then inserted in aQGridLayout
.
Here the header of Cell:#pragma once #include <QFrame> class QLabel; class QHBoxLayout; class QVBoxLayout; class Cell : public QFrame { Q_OBJECT public: explicit Cell(QWidget *parent = nullptr); void setValue(int value); int getValue() const; QSize minimumSizeHint() const override; private: QVBoxLayout *m_cellContainer; QHBoxLayout *m_center; QHBoxLayout *m_top; QHBoxLayout *m_bottom; QLabel *m_valueLabel; int m_value; void initCenter(); void initTop(); void initBottom(); };
Here the cpp of Cell:
#include "view/CellPanel.h" #include <QHBoxLayout> #include <QVBoxLayout> #include <QLabel> Cell::Cell(QWidget *parent) : QFrame{parent}, m_cellContainer{new QVBoxLayout()}, m_center{new QHBoxLayout()}, m_top{new QHBoxLayout()}, m_bottom{new QHBoxLayout()}, m_valueLabel{new QLabel("C")}, m_value{0} { initCenter(); initTop(); initBottom(); setFrameStyle(QFrame::Panel); setLineWidth(2); setLayout(m_cellContainer); m_cellContainer->addLayout(m_top); m_cellContainer->addLayout(m_center); m_cellContainer->addLayout(m_bottom); } void Cell::setValue(int value) { m_value = value; m_valueLabel->setText(QString::number(value)); } int Cell::getValue() const { return m_value; } QSize Cell::minimumSizeHint() const { return m_center->sizeHint(); } void Cell::initCenter() { auto font = m_valueLabel->font(); font.setPointSize(font.pointSize() * 2); m_valueLabel->setFont(font); m_center->addWidget(new QLabel("L"), 0, Qt::AlignLeft); m_center->addWidget(m_valueLabel, 0, Qt::AlignCenter); m_center->addWidget(new QLabel("R"), 0, Qt::AlignRight); } void Cell::initTop() { m_top->addWidget(new QLabel("T L"), 0, Qt::AlignLeft | Qt::AlignTop); m_top->addWidget(new QLabel("T C"), 0, Qt::AlignCenter | Qt::AlignTop); m_top->addWidget(new QLabel("T R"), 0, Qt::AlignRight | Qt::AlignTop); } void Cell::initBottom() { m_bottom->addWidget(new QLabel("B L"), 0, Qt::AlignLeft | Qt::AlignBottom); m_bottom->addWidget(new QLabel("B C"), 0, Qt::AlignCenter | Qt::AlignBottom); m_bottom->addWidget(new QLabel("B R"), 0, Qt::AlignRight | Qt::AlignBottom); }
Here the cells are inserted as Blocks into a
QGridLayout
:#pragma once #include <QFrame> class QGridLayout; class BlockPanel: public QFrame { Q_OBJECT public: explicit BlockPanel(QWidget *parent = nullptr); private: QGridLayout *m_blocks; void initBlocks(); };
#include "view/BlockPanel.h" #include "view/CellPanel.h" #include <QGridLayout> BlockPanel::BlockPanel(QWidget *parent) : QFrame{parent}, m_blocks(new QGridLayout(this)) { initBlocks(); } void BlockPanel::initBlocks() { constexpr int blockSize = 3; for (int blockRow = 0; blockRow < blockSize; ++blockRow) { for (int blockColumn = 0; blockColumn < blockSize; ++blockColumn) { m_blocks->addWidget(new Cell(), blockRow, blockColumn); } } Cell cell; m_blocks->setRowMinimumHeight(1, cell.baseSize().height()); }
Any ideas, how to fix this?
Thanks in advance! :-)