How to align QFormLayout in a QGroupBox by Horizontal center - c++

I can`t understand how to align form layout in groupbox by center.
This is how i want it to work. (Correct)
This is how it works now. (Wrong)
Here is the code.
mainWinGroupBox = new QGroupBox(tr("Window Settings"));
mainWinGroupBox->setAlignment(Qt::AlignHCenter);
auto fWinLayout = new QFormLayout;
fWinLayout->setFormAlignment(Qt::AlignHCenter);
fWinLayout->addRow(tr("&Tray:"), trayCheckBox);
WindowWidthSB->setFixedSize(42, 20);
WindowWidthSB->setRange(0, 1920);
WindowWidthSB->setSingleStep(10);
fWinLayout->addRow(tr("&Window Width:"), WindowWidthSB);
WindowHeightSB->setFixedSize(42, 20);
WindowHeightSB->setRange(0, 1080);
WindowHeightSB->setSingleStep(10);
fWinLayout->addRow(tr("&Window Height:"), WindowHeightSB);
mainWinGroupBox->setLayout(fWinLayout);

You can align your labels with this property QFormLayout::labelAlignment.

Related

wxlistctrl align column image on center

As the title, I can't align an image to the center of a cell in a wxwidget listctrl. As in the attached image you can see the image is everytime aligned to the left. How can I put in the center?
Thanks a lot in advance.
wxBitmap imgCheck(wxT("./immagini/checked.png"), wxBITMAP_TYPE_PNG);
wxBitmap imgUnCheck(wxT("./immagini/unchecked.png"), wxBITMAP_TYPE_PNG);
...
lstUtenti = new wxListCtrl(this,wxID_ANY, wxDefaultPosition, wxSize(780, -1), wxLC_REPORT|wxLC_SINGLE_SEL);
...
wxImageList* imgCheckUncheck = new wxImageList(32,32);
lstUtenti->AssignImageList(imgCheckUncheck, wxIMAGE_LIST_SMALL);
int check = imgCheckUncheck->Add(imgCheck);
int unCheck = imgCheckUncheck->Add(imgUnCheck);
...
lstUtenti->AppendColumn("Notifiche", wxLIST_FORMAT_CENTRE);
lstUtenti->AppendColumn("Eventi", wxLIST_FORMAT_CENTRE);
....
lstUtenti->SetItem(0, 4, "", unCheck);
lstUtenti->SetItem(0, 5, "", check);

QtCharts Axis Alignment Center

I'm trying to use QtCharts with X-Axis and Y-Axis in the center of chart.
Therefore the center point will locate in the middle of my QtChart... There are options to alignment axis to the top/bottom or left/right (addAxis(QValueAxis*,Qt::AlignTop)). But, there is no option to align it to the center. When I use AlignCenter as addAxis argument, I get an error.
Any Help?
Tanks.
Edit (Providing code and error):
QChart *BScopeChart = new QChart();
QLineSeries *BScopeSerie = new QLineSeries(this);
BScopeChart->setMargins(QMargins(0, 0, 0, 0));
QValueAxis *BScopeAxisX = new QValueAxis;
BScopeAxisX->setRange(-50, 50);
QValueAxis *BScopeAxisY = new QValueAxis;
BScopeAxisY->setRange(-5, 5);
BScopeChart->addAxis(BScopeAxisY, Qt::AlignLeft); // I need this Line change to something like: BScopeChart->addAxis(BScopeAxisY, Qt::AlignCenter)
BScopeChart->addAxis(BScopeAxisX, Qt::AlignBottom); // I need this Line change to something like: BScopeChart->addAxis(BScopeAxisX, Qt::AlignCenter);
ui.widgetBScopeQChart->setChart(BScopeChart);
and when I change those two lines to:
BScopeChart->addAxis(BScopeAxisY, Qt::AlignCenter);
BScopeChart->addAxis(BScopeAxisX, Qt::AlignCenter);
I face this error:
ErrorScreenshot

How can I stretch a QLayout or QFrame, nested within a bigger layout?

I currently have this code set up to create a sidebar and I'm not entirely sure how to stretch it so that the left, top, and bottom sides touch the edge of the window.
QFrame *sidebar = new QFrame;
QLabel *sideItemA = new QLabel("Item A");
QLabel *sideItemB = new QLabel("Item B");
QVBoxLayout *sidebarLayout = new QVBoxLayout;
sidebarLayout->addWidget(sideItemA);
sidebarLayout->addWidget(sideItemB);
sidebarLayout->addStretch();
sidebar->setLayout(sidebarLayout);
sidebar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
sidebar->setStyleSheet("background-color:#FFFFFF");
sidebar->setMinimumWidth(150);
mainLayout->addWidget(sidebar);
Here is a screenshot of what the above code looks like:
I've tried doing this using nested layouts too and I get the same result. Any pointers? Is this even the best way to do it?

How do I align a widget?

I cannot move the widget into the layout (QGridLayout). You need to move the "label shift" to the other widgets. That they were close. How can I do that?
QLabel * label_answer = new QLabel(this);
label_answer->setText("label_shift");
label_answer->setFont(params_font);
label_answer->setObjectName(QStringLiteral("label_answer_%1").arg(count-1));
lay->addWidget(main_label, i,0, Qt::AlignLeft);
lay->addWidget(box_input_value, i, 1, Qt::AlignLeft);
lay->addWidget(label_answer, i, 2, Qt::AlignLeft); // label_shift
You could add a extra column to the gridlayout, have the spinbox span 2 columns, which would mean the space needed in the label row is after the label, instead of before it

QScrollBar + QScrollAera in QTabWidget

My question is simple : how can I set a QScrollBar in my QScrollArea. I have tested a lot of things but nothing work ... Maybe it's a problem to set a QScrollArea in a QTabWidget ? Here is the code :
void GamesWindow::createTabSucces()
{
std::string nameImg;
_succesPage = new QWidget(_tab);
_tab->addTab(_succesPage, " Succes ");
scrollArea = new QScrollArea(_succesPage);
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setFixedSize(500,500);
/* Integration of QScrollBar */
for (int i = 0; i < 45; i++)
{
nameImg = "img/allAchiv/";
nameImg += intToString(i + 1);
nameImg += ".jpg";
_imgSucc[i] = new QLabel(scrollArea);
_imgSucc[i]->setPixmap(QPixmap(QString(nameImg.c_str())));
_imgSucc[i]->setGeometry((14 + (85 * (i % 5))), 46 + ((i / 5) * 85), 60, 60);
}
}
In fact, I add pictures in a tab where is created a QScrollArea (like 8-9 lines of pictures) but only 5 are visible, the others are hide, because they are at the bottom, out of the defined zone.
Any idea ? Thank's.
You must:
add a layout to your page (QVBoxLayout)
add the scroll area to that page layout
add a layout to the viewport() widget in the scroll area (QVBoxLayout)
add your QLabels to that viewport layout
This way you won't need to call setGeometry on each label
You need to set a widget to your scroll area and add your pictures to the widget's layout. Check QScrollArea::setWidget(QWidget *widget)
I'm almost sure that you can't add scroll to a tab widget but my idea is just to try make more tabs that can be shown and see if the slider comes up by default.