Qt

Qt: Bruk av QScrollArea, svar hvorfor rullefeltet ikke kan vises.

Qt Use Qscrollarea



Her er effekten av en enkel QScrollArea:
bilde

Følgende er implementeringen av ovennevnte gif-animasjon:



//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)

Følgende er tre rullefeltstrategier.



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.

Om grunnen til at rullefeltet ikke kan vises:
1. Innstilling av rullestrategi.
2. Hvorvidt du skal stille scrollArea-> setWidgetResizable (false) hvis koden opprettes, er standard false.
3. Hvis du drar rulleområdet direkte fra ui-designeren, er attributtet setWidgetResizable () sant som standard. Dette er ikke det samme som kodegenerering ... Se bildet nedenfor, ikke Etter endring er standard sant.



bilde