-
StackOverflow 文件
-
Qt 教程
-
QListView 上的標頭
-
自定義 QListView 宣告
/*!
* \class MainMenuListView
* \brief The MainMenuListView class is a QListView with a header displayed
* on top.
*/
class MainMenuListView : public QListView
{
Q_OBJECT
/*!
* \class Header
* \brief The header class is a nested class used to display the header of a
* QListView. On each instance of the MainMenuListView, a header will
* be displayed.
*/
class Header : public QWidget
{
public:
/*!
* \brief Constructor used to defined the parent/child relation
* between the Header and the QListView.
* \param parent Parent of the widget.
*/
Header(MainMenuListView* parent);
/*!
* \brief Overridden method which allows to get the recommended size
* for the Header object.
* \return The recommended size for the Header widget.
*/
QSize sizeHint() const;
protected:
/*!
* \brief Overridden paint event which will allow us to design the
* Header widget area and draw some text.
* \param event Paint event.
*/
void paintEvent(QPaintEvent* event);
private:
MainMenuListView* menu; /*!< The parent of the Header. */
};
public:
/*!
* \brief Constructor allowing to instanciate the customized QListView.
* \param parent Parent widget.
* \param header Text which has to be displayed in the header
* (Header by default)
*/
MainMenuListView(QWidget* parent = nullptr, const QString& header = QString("Header"));
/*!
* \brief Catches the Header paint event and draws the header with
* the specified text in the constructor.
* \param event Header paint event.
*/
void headerAreaPaintEvent(QPaintEvent* event);
/*!
* \brief Gets the width of the List widget.
* This value will also determine the width of the Header.
* \return The width of the custom QListView.
*/
int headerAreaWidth();
protected:
/*!
* \brief Overridden method which allows to resize the Header.
* \param event Resize event.
*/
void resizeEvent(QResizeEvent* event);
private:
QWidget* headerArea; /*!< Header widget. */
QString headerText; /*!< Header title. */
};