GG2013
26th June 2013, 06:32
Hallo,
I am pretty new to Qt and trying to develop a page as shown in the attached figure. Basically I would like all 3 pies to be uniformly separated at the first row, and the table to appear at the second row.
9186
With QGridLayout it seems like the multiple widgets are not automatically re-sized and placed. Initially without lines 12-17, only the table was displayed (at the top).
With line 15 commented, I get the page as shown in figure i.e the first pie is displayed partially. I also tried to use QHBoxLayout for the 3 pies, and then use QVBoxLayout- still the same problem.
Could anybody help me please:
#1 To sort out the above problem
#2 Also, is there any way to place a border around each widget (setSpacing allows some gap)?
Thank you in advance.
TabSix_PageSix::TabSix_PageSix(QWidget *parent): QWidget(parent)
{
PaintWidgetPie *pie1 = new PaintWidgetPie;
PaintWidgetPie *pie2 = new PaintWidgetPie;
PaintWidgetPie *pie3 = new PaintWidgetPie;
QSizePolicy spVertical(QSizePolicy::Preferred, QSizePolicy::Preferred);
spVertical.setVerticalStretch(1);
QSizePolicy spHorizontal(QSizePolicy::Preferred, QSizePolicy::Preferred);
spHorizontal.setHorizontalStretch(1);
pie1->setSizePolicy(spVertical);
pie2->setSizePolicy(spVertical);
pie3->setSizePolicy(spVertical);
//pie1->setSizePolicy(spHorizontal);
pie2->setSizePolicy(spHorizontal);
pie3->setSizePolicy(spHorizontal);
//QLabel *label = new QLabel (tr("Web Traffic Breakdown by Protocol Graph"));
QGroupBox *gbox = new QGroupBox;
gbox->setTitle(tr("Web Traffic Breakdown by Protocol Table"));
gbox->setStyleSheet("QGroupBox::title {"
"subcontrol-position:top-center;"
"color: #000000;"
"background-color: #C2DFFF;"
"padding:2 560 2 565;"
"} QGroupBox {font-size: 20px;}"
); //font doesn't work with QGroupBox::title, all parameters need to be set in one go
QTableWidget *tableWidget = new QTableWidget(this);
tableWidget->setRowCount(2);
tableWidget->setColumnCount(8);
tableWidget->setItem(0,0, new QTableWidgetItem("25:08:2010"));
tableWidget->setItem(0,1, new QTableWidgetItem("10.131.344 kByte"));
QStringList labels;
labels <<tr("Date:Time") << tr("FWI Traffic");
tableWidget->setHorizontalHeaderLabels(labels);
tableWidget->horizontalHeader()->show();
tableWidget->verticalHeader()->hide();
tableWidget->setShowGrid(true);
tableWidget->setStyleSheet("border-color: 10px blue;");
QGridLayout *gLayout = new QGridLayout;
gLayout->addWidget(pie1, 0, 0);
gLayout->addWidget(pie2, 0, 1);
gLayout->addWidget(pie3, 0, 2);
gLayout->addWidget(tableWidget, 1,0);
this->setLayout(gLayout);
}
I am pretty new to Qt and trying to develop a page as shown in the attached figure. Basically I would like all 3 pies to be uniformly separated at the first row, and the table to appear at the second row.
9186
With QGridLayout it seems like the multiple widgets are not automatically re-sized and placed. Initially without lines 12-17, only the table was displayed (at the top).
With line 15 commented, I get the page as shown in figure i.e the first pie is displayed partially. I also tried to use QHBoxLayout for the 3 pies, and then use QVBoxLayout- still the same problem.
Could anybody help me please:
#1 To sort out the above problem
#2 Also, is there any way to place a border around each widget (setSpacing allows some gap)?
Thank you in advance.
TabSix_PageSix::TabSix_PageSix(QWidget *parent): QWidget(parent)
{
PaintWidgetPie *pie1 = new PaintWidgetPie;
PaintWidgetPie *pie2 = new PaintWidgetPie;
PaintWidgetPie *pie3 = new PaintWidgetPie;
QSizePolicy spVertical(QSizePolicy::Preferred, QSizePolicy::Preferred);
spVertical.setVerticalStretch(1);
QSizePolicy spHorizontal(QSizePolicy::Preferred, QSizePolicy::Preferred);
spHorizontal.setHorizontalStretch(1);
pie1->setSizePolicy(spVertical);
pie2->setSizePolicy(spVertical);
pie3->setSizePolicy(spVertical);
//pie1->setSizePolicy(spHorizontal);
pie2->setSizePolicy(spHorizontal);
pie3->setSizePolicy(spHorizontal);
//QLabel *label = new QLabel (tr("Web Traffic Breakdown by Protocol Graph"));
QGroupBox *gbox = new QGroupBox;
gbox->setTitle(tr("Web Traffic Breakdown by Protocol Table"));
gbox->setStyleSheet("QGroupBox::title {"
"subcontrol-position:top-center;"
"color: #000000;"
"background-color: #C2DFFF;"
"padding:2 560 2 565;"
"} QGroupBox {font-size: 20px;}"
); //font doesn't work with QGroupBox::title, all parameters need to be set in one go
QTableWidget *tableWidget = new QTableWidget(this);
tableWidget->setRowCount(2);
tableWidget->setColumnCount(8);
tableWidget->setItem(0,0, new QTableWidgetItem("25:08:2010"));
tableWidget->setItem(0,1, new QTableWidgetItem("10.131.344 kByte"));
QStringList labels;
labels <<tr("Date:Time") << tr("FWI Traffic");
tableWidget->setHorizontalHeaderLabels(labels);
tableWidget->horizontalHeader()->show();
tableWidget->verticalHeader()->hide();
tableWidget->setShowGrid(true);
tableWidget->setStyleSheet("border-color: 10px blue;");
QGridLayout *gLayout = new QGridLayout;
gLayout->addWidget(pie1, 0, 0);
gLayout->addWidget(pie2, 0, 1);
gLayout->addWidget(pie3, 0, 2);
gLayout->addWidget(tableWidget, 1,0);
this->setLayout(gLayout);
}