2

画面の左側に複数の項目 (テキスト) を含むメニューが必要なアプリケーションに取り組んでいます。表示したい項目は、実際のテキストとハイライト バーだけです。また、次のようにハイライト バーを変更したいと思います。アニメーション化して、ある選択から次の選択にスライドできます b. デフォルトのハイライト カラーの代わりに、角が丸いカスタム ピックスマップを使用できます

QListWidget とスタイルシートを使用してみましたが、ある程度成功しましたが、この方法を使用してハイライト バーの角を丸くすることはできないと思います。また、あるアイテムから次のアイテムへのバーの動きをアニメーション化できるかどうかもわかりません。

preset_list_view->setStyleSheet("QListView {color: rgb(230, 230, 230); background-color: rgba(0,0,0,0); border-style: none} QListView::item:selected {background-image: url(:/ui_resources/elements-preset_select/highlight_bar_270x30-black_bg.bmp)}");

私はオンラインですべてを見てきましたが、あまり見つかりませんでした。QListWidget のデリゲートを変更するという言及がいくつかありますが、説明はあいまいです。これでアニメーションの問題が解決するかどうかもわかりません。

何か案は?

4

2 に答える 2

4

QListWidget の上に半透明の不活性ウィジェットを配置し、選択が変更されたときにそれをアニメーション化できます。ただし、通常の選択インジケーターを無効にするデリゲートも必要です。

実際の例:

#include <QListWidget>
#include <QFrame>
#include <QPropertyAnimation>
#include <QStyledItemDelegate>

class RemoveSelectionDelegate : public QStyledItemDelegate {
public:
    RemoveSelectionDelegate(QObject *parent = 0)
        : QStyledItemDelegate(parent) {
    }

    void paint(QPainter *painter, const QStyleOptionViewItem &option,
               const QModelIndex &index) const {
        // Call the original paint method with the selection state cleared
        // to prevent painting the original selection background
        QStyleOptionViewItemV4 optionV4 =
            *qstyleoption_cast<const QStyleOptionViewItemV4 *>(&option);
        optionV4.state &= ~QStyle::State_Selected;
        QStyledItemDelegate::paint(painter, optionV4, index);
    }
};

class ListWidget : public QListWidget {
    Q_OBJECT
public:
    ListWidget(QWidget *parent = 0)
        : QListWidget(parent)
        , selectionFrame(this)
        , animation(&selectionFrame, "geometry") {
        // Create a semi-transparent frame that doesn't interact with anything
        selectionFrame.setAttribute(Qt::WA_TransparentForMouseEvents);
        selectionFrame.setFocusPolicy(Qt::NoFocus);

        // You can put your transparent image in that stylesheet
        selectionFrame.setStyleSheet("background: solid rgba(0, 0, 125, 25%);");
        selectionFrame.hide();
        animation.setDuration(250);
        animation.setEasingCurve(QEasingCurve::InOutBack);

        connect(this,
                SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
                SLOT(updateSelection(QListWidgetItem*)) );        
        setItemDelegate(new RemoveSelectionDelegate(this));
    }

private slots:
    void resizeEvent(QResizeEvent *e) {
        QListWidget::resizeEvent(e);
        updateSelection(currentItem());
    }

    void updateSelection(QListWidgetItem* current) {
        animation.stop();
        if (!current) {
            selectionFrame.hide();
            return;
        }
        if (!selectionFrame.isVisible()) {
            selectionFrame.setGeometry(visualItemRect(current));
            selectionFrame.show();
            return;
        }
        animation.setStartValue(selectionFrame.geometry());
        animation.setEndValue(visualItemRect(current));
        animation.start();
    }
private:
    QFrame selectionFrame;
    QPropertyAnimation animation;
};
于 2011-09-01T22:30:27.613 に答える
1

したがって、テキストだけの場合は、QLabels を備えた QDockwidget を使用しないでください。

たとえば、左側にある「Qt Designer の「ウィジェット ボックス」を見てください。それをドラッグして上部に配置できます。それはあなたが探しているものですか?

ドックウィジェットは好きなように移動できます。

于 2011-09-01T19:03:20.550 に答える