Pergunta

I am embedding some QTableWidget(s) recursively inside of each other. The final GUI will have 4 to a couple thousand squares. Here is an example screenshot only showing 16 squares.:

...

Because there are so many squares (thousands) that need to be displayed I need the minimum size of each square to be something like 5x5 pixels.

The problem is that I used my mouse to size the window as small as possible... and then I got to what you see in the screenshot! The screenshot has each square being about 18x18 pixels... which isn't small enough to fit thousands of squares on a screen. Something is preventing me from using my mouse to size the squares smaller!

How can I make the squares in this screenshot have a smaller minimum size?

main.cpp:

#include "TableWidget.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    TableWidget *x1 = new TableWidget(2,2);
    for(int i = 0; i < x1->rowCount(); i++) {
        for(int j = 0; j < x1->columnCount(); j++) {
            x1->setCellWidget(i,j,new TableWidget(2,2));
        }
    }

    QGridLayout *layout = new QGridLayout;
    layout->addWidget(x1, 0, 0);

    QWidget *window = new QWidget;
    window->setLayout(layout);
    window->show();

    return a.exec();
}

TableWidget.h:

class TableWidget : public QTableWidget
{
    Q_OBJECT
public:
    TableWidget(int rows, int columns, QWidget *parent = 0);
private:
signals:
public slots:
};

TableWidget.cpp:

TableWidget::TableWidget(int rows, int columns, QWidget *parent) :
    QTableWidget(rows,columns,parent)
{
    //------
    QTableWidget::horizontalHeader()->hide();
    QTableWidget::verticalHeader()->hide();
    //------
    QTableWidget::horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    QTableWidget::verticalHeader()->setResizeMode(QHeaderView::Stretch);
    //------
    QTableWidget::setEditTriggers(QAbstractItemView::NoEditTriggers);
    //------
    QTableWidget::setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    QTableWidget::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    //------
    QTableWidget::horizontalHeader()->setMinimumSectionSize(1);
    QTableWidget::verticalHeader()->setMinimumSectionSize(1);
    QTableWidget::horizontalHeader()->setDefaultSectionSize(1);
    QTableWidget::verticalHeader()->setDefaultSectionSize(1);
    // FIXME, the minimum size is not 1 pixel... it is like 10 pixels...
    //------
    QTableWidget::setSelectionMode(QAbstractItemView::NoSelection);
}

UPDATE - As per comments below I tried rendering many more squares and here is 1024:

enter image description here

Foi útil?

Solução

On my WindowsXP, I can't shrink most programs lower than 148x96. It might have absolutely nothing to do with your Widgets.

Test with 256+ squares, and tell us how big each square is.

Windows (and whatever it is you're using) have this limitation to guarantee the users are able to see the bottons on the top, a few letters of the title, and enough room for scrollbars. And so the user doesn't lose the program they shrunk to 3x2px.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top