Qt

Qt:QScrollAreaを使用しているので、スクロールバーが表示されない理由を答えてください。



Qt Use Qscrollarea



単純なQScrollAreaの効果は次のとおりです。
画像

以下は、上記のgifアニメーションの実装です。



//The picture is 300*300. Put the picture in the label. QImage image('./1.png') QLabel *label = new QLabel(this) label->resize(300,300) label->setPixmap(QPixmap::fromImage(image)) //Create a scrolling area. QScrollArea *scrollArea = new QScrollArea //Put the label control into the scrolling area. Note that only one control can be set, and one control can be added to it, and only the last added control will be displayed. scrollArea->setWidget(label) //Set the alignment format. scrollArea->setAlignment(Qt::AlignCenter) //Set the strategy for horizontal and vertical scroll bars. The default is the following strategy. //scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded) //scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded) //Set whether to automatically adjust the size of the widget. The default is false. //scrollArea->setWidgetResizable(false) QHBoxLayout *layout = new QHBoxLayout(this) layout->addWidget(scrollArea) this->resize(200,200)

以下は、3つのスクロールバー戦略です。

Qt::ScrollBarAsNeeded 0 The scroll bar is turned on or off as needed. The default strategy. According to the actual size of the control in the scroll area and the size of the scroll area. Qt::ScrollBarAlwaysOff 1 The scroll bar is always closed. Qt::ScrollBarAlwaysOn 2 The scroll bar is always on.

スクロールバーが表示されない理由について:
1.スクロール戦略の設定。
2.コードが作成された場合にscrollArea-> setWidgetResizable(false)を設定するかどうか、デフォルトはfalseです。
3. uiデザイナーから直接スクロール領域をドラッグすると、setWidgetResizable()属性はデフォルトでtrueになります。これはコード生成と同じではありません...変更後ではなく、下の図を参照してください。デフォルトはtrueです。



画像