Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Label cut off
Qt 6.11 is out! See what's new in the release blog

Label cut off

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 261 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • StefanoDS Offline
    StefanoDS Offline
    StefanoD
    wrote on last edited by
    #1

    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, that QLabel which represents the current value, is cut-off:

    Bildschirmfoto 2024-12-20 um 12.13.13.jpg
    In this mockup, the value "C" is cut-off.

    Each line is represented by a QHBoxLayout and all lines are wrapped up with QVBoxLayout. The cells are then inserted in a QGridLayout.
    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! :-)

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved