0

私は以下のようなコードを持っています。データベースにいくつかのデータがあり、それを表示するためにビュー構造を作成する必要があります。私はQtプログラミングの経験があまりなく、PHP、HTML、CSSでもっと多くのものを作りました。HTMLのようなことをする必要があります-余分なスタイルのないボックス(たとえばdiv)があり、データの中に入れると、このdivタグはすべてのデータの内部を表示します。しかし、次のコードでは、ファイルからロードされたウィジェットからのデータの一部しか取得していません。MainWindowでのGridLayoutの動作はdiv style="max-width: 200px; max-height: 200px; overflow:hidden「」に似ています。また、子ファイルのレイアウト要素も同じ動作をします。

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "databasemanager.h"
#include "ycexception.h"
#include <QDebug>
#include <QSqlQuery>

#include <QtUiTools>

#include <QLabel>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    createStructureFromDb();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::createStructureFromDb() {
    try {
        dbManager = new DatabaseManager();
    }
    catch(YCException e) {
        //TODO: show dialog with message
        qDebug() << e.what();
        exit(-1);
    }

    QSqlQuery groupsQuery = dbManager->getGroups();
    while(groupsQuery.next()) {
        Group group;
        group.setIdGroup(groupsQuery.value(0).toInt());
        group.setName(groupsQuery.value(1).toString());

        QUiLoader loader;
        QFile file(":/forms/group.ui");
        file.open(QFile::ReadOnly);
        QWidget *formWidget = loader.load(&file);
        file.close();
        (formWidget->findChild<QLabel*>("groupName"))->setText(group.getName());
        ui->gridLayout->addWidget(formWidget);

        QVBoxLayout* groupItems = formWidget->findChild<QVBoxLayout*>("groupItems");

        QSqlQuery cardsQuery = dbManager->getGroupCards(group.getIdGroup());
        while(cardsQuery.next()) {
            Card card;
            card.setIdCard(cardsQuery.value(0).toInt());
            card.setContent(cardsQuery.value(1).toString());
            card.setDueDate(cardsQuery.value(2).toString());
            card.setIdGroup(cardsQuery.value(3).toInt());

            group.addCard(card);

            QFile file(":/forms/card.ui");
            QWidget *cardWidget = loader.load(&file);
            file.close();

            (cardWidget->findChild<QLabel*>("contentLabel"))->setText(card.getContent());
            (cardWidget->findChild<QLabel*>("dueDateLabel"))->setText(card.getDueDate());

            groupItems->addWidget(cardWidget);
        }
        groups.insert(group.getIdGroup(), group);
    }

    ui->label->setText("really long textreally long textreally long textreally long textreally long textreally long textreally long textreally long textreally long textreally long textreally long text");
    this->layout()->activate();
}
4

1 に答える 1

1

overflow:hiddenWebテクノロジーの知識がほとんどない私のような人にはほとんど明白です(しかし、私はそれをグーグルで検索できます)。しかし、スクロールバーが必要だと言うことは、はるかに表現力豊かです...私はこのページを使用して、必要なものを理解しました。

だから、あなたが望むもののために:htmlのdivのようGridLayoutではありません。ウィジェットのコンテンツをスクロールする場合は、ウィジェットをQScrollAreaに配置し、そのスクロール領域を最初にウィジェットが含まれていたGridLayoutのセルに配置する必要があります。

すなわち:

  • overflow:visible不可能
  • overflow:hidden:デフォルトの動作
  • overflow:scroll:QScrollAreaを使用する
  • overflow:auto:QScrollAreaを使用する
  • overflow:inherit:可能ですが、これを行うにはかなりのコードを書く必要があります。また、うまく設計されたインターフェースでは役に立たない
于 2012-11-29T21:35:08.660 に答える