PDA

View Full Version : vertical slider



TomASS
27th November 2009, 09:06
Hi

I'va a simple window (QMainWindow):


FormTransportOperacje::FormTransportOperacje(QStri ng ID_transport, QWidget *parent) : QMainWindow(parent)
{
this->setMaximumHeight(400);
QWidget *base = new QWidget();
QGridLayout *layout = new QGridLayout(base);
QSqlQuery query("SELECT Imie, Nazwisko, Data_operacji, Nazwa_operacji FROM m_transporty_operacje AS Top LEFT JOIN m_uzytkownicy AS U ON (U.ID_u=Top.ID_uzytkownik) WHERE ID_transport="+ID_transport+" ORDER BY Data_operacji DESC");

int i = 0;
while (query.next()) {
QGroupBox *GbTMP= new QGroupBox(query.value(3).toString());
GbTMP->setMinimumHeight(70);
GbTMP->setMaximumHeight(70);
QGridLayout *layoutTMP = new QGridLayout();
QDateTime DTData = query.value(2).toDateTime();

QLabel *Uzytkownik = new QLabel(query.value(0).toString()+" "+query.value(1).toString());
QLabel *Data_operacji = new QLabel(DTData.toString("yyyy-MM-dd HH:mm:ss"));

GbTMP->setLayout(layoutTMP);
layout->addWidget(GbTMP,i++,0,1,1);
}

base->show();
this->setCentralWidget(base);
this->move(((QApplication::desktop()->width()-this->width())/2),((QApplication::desktop()->height()-this->height())/2));

}

And when there are many records, the window extends beyond the boundary of screen.

How can I "freez" the size of window, and add the verticalslider when the content does not fit in the window?

nish
27th November 2009, 09:53
use a QScrollArea as your central widget.

TomASS
28th November 2009, 17:11
I've used:

QScrollArea *Sa = new QScrollArea();
Sa->setWidgetResizable(true);
Sa->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
Sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
QWidget *base = new QWidget(Sa);


.
.
.
base->show();
this->setCentralWidget(Sa);

and Scroll has appeard but ther is no active :/

wysota
28th November 2009, 18:16
Did you use QScrollArea::setWidget()?

TomASS
29th November 2009, 00:30
Thanks! It's working.