Unsolved GUI was not proper for all resolutions
-
Hi,
I am using three QGroupbox in QHBoxLayout, and my groupboxes shout not resize it should be constans for that i am setting setFixedSize, but this was effecting GUI when I am running in other resolutions.
My resolution is 1600x900, here it was proper, but when running in 1920x1280 it was not proper, groupboxes getting smaller and gui doesn't look good.You can see following code for reference:
QHBoxLayout *connectionLayout = new QHBoxLayout;
connectionLayout->setSpacing(2);
ui->connectionBox->setMinimumSize(160,150);
ui->connectionBox->setMaximumSize(160,150);
ui->ProgrammerBox->setMinimumSize(320,150);
ui->ProgrammerBox->setMaximumSize(320,150);
ui->powerBox->setMinimumSize(330,150);
ui->powerBox->setMaximumSize(330,150);
connectionLayout->addWidget(ui->connectionBox);
connectionLayout->addWidget(ui->ProgrammerBox);
connectionLayout->addWidget(ui->powerBox);
// connectionLayout->setSizeConstraint(QLayout::SetFixedSize);
mainBoxLayout->addLayout(connectionLayout);Thanks in advance.
-
@Apeksha said in GUI was not proper for all resolutions:
my groupboxes shout not resize
instead of using
setMinimumSize
andsetMaximumSize
could you try usingsetSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
? that should look good on all resolutions and not expand/shrink. -
@VRonin said in GUI was not proper for all resolutions:
setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
thank you for response.
it's not working -
this is my actual gui code:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// QRect screenSize = desktop.availableGeometry(this);
// this->resize(QSize(screenSize.width * 0.7f, screenSize.height * 0.7f));
// qDebug()<<"screen geometry is"<<screenGeometry;
// QDesktopWidget dw;
// int x=dw.width();
// int y=dw.height();
ui->centralWidget->setStyleSheet("background-color:rgb(221, 221, 221)");
ui->menuBar->setStyleSheet("QMenuBar{background-color:rgb(221, 221, 221)} QMenu:hover {background-color:white; selection-color:white;}");
ui->modeComboBox->addItem("Secured1");
ui->modeComboBox->addItem("Secured2");timer = new QTimer(this); upgradetimer = new QTimer(this); uploadtimer = new QTimer(this); canceltimer = new QTimer(this); programtimer = new QTimer(this);
#if 1
QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->setSpacing(5); ui->MainBox->setAlignment(Qt::AlignTop); mainLayout->addWidget(ui->MainBox); mainLayout->addWidget(ui->txtLog); ui->txtLog->setReadOnly(true); QScrollBar *sb = ui->txtLog->horizontalScrollBar(); ui->txtLog->setLineWrapMode(QTextEdit::NoWrap); sb->setValue(sb->maximum()); ui->centralWidget->setLayout(mainLayout); QVBoxLayout *mainBoxLayout= new QVBoxLayout; mainBoxLayout->setSpacing(0); QWidget *topWidget = new QWidget; QVBoxLayout *step1Layout = new QVBoxLayout(topWidget); step1Layout->setSpacing(1); step1Layout->addStretch(0); ui->label_1->setMinimumSize(100,10); ui->label_1->setMaximumSize(100,10); ui->line->setMaximumSize(811,15); ui->line->setMinimumSize(811,15); step1Layout->addWidget(ui->label_1,0,Qt::AlignTop); step1Layout->addWidget(ui->line,0,Qt::AlignTop);
// topWidget->setFixedHeight(30);
topWidget->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
mainBoxLayout->addWidget(topWidget);QHBoxLayout *connectionLayout = new QHBoxLayout; connectionLayout->setSpacing(2);
// ui->connectionBox->setMinimumSize(160,150);
// ui->connectionBox->setMaximumSize(160,150);
// ui->ProgrammerBox->setMinimumSize(320,150);
// ui->ProgrammerBox->setMaximumSize(320,150);
// ui->powerBox->setMinimumSize(330,150);
// ui->powerBox->setMaximumSize(330,150);ui->connectionBox->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); ui->ProgrammerBox->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); ui->powerBox->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); connectionLayout->addWidget(ui->connectionBox); connectionLayout->addWidget(ui->ProgrammerBox); connectionLayout->addWidget(ui->powerBox); mainBoxLayout->addLayout(connectionLayout); QWidget *top2Widget = new QWidget; QVBoxLayout *step2Layout = new QVBoxLayout(top2Widget); step2Layout->setSpacing(1); step2Layout->addStretch(0); step2Layout->addWidget(ui->label_2); step2Layout->addWidget(ui->line_2);
// top2Widget->setFixedHeight(33);
top2Widget->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
mainBoxLayout->addWidget(top2Widget);// ui->contentWidget->setMinimumSize( 820, 200 );
ui->contentWidget->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
QHBoxLayout *ConfigurationLayout = new QHBoxLayout;
QScrollArea *scrollArea = new QScrollArea;
// scrollArea->setStyleSheet("QScrollArea {background-color:#C0C0C0;}");
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setWidget(ui->contentWidget);
scrollArea->setWidgetResizable(true);
ConfigurationLayout->addWidget(scrollArea);
mainBoxLayout->addLayout(ConfigurationLayout);QWidget *top3Widget = new QWidget; QVBoxLayout *step3Layout = new QVBoxLayout(top3Widget); step3Layout->setSpacing(1); step3Layout->addStretch(1); step3Layout->addWidget(ui->label_3); step3Layout->addWidget(ui->line_3);
// top3Widget->setFixedHeight(33);
top3Widget->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
mainBoxLayout->addWidget(top3Widget);QHBoxLayout *operationLayout = new QHBoxLayout;
// ui->operationBox->setMinimumSize(820,195);
ui->operationBox->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
//ui->operationBox->setMaximumSize(820,195);
operationLayout->addWidget(ui->operationBox);
mainBoxLayout->addLayout(operationLayout);
ui->MainBox->setLayout(mainBoxLayout); -
Hi
Can we set default resolution as 1600x900 in qt app, so it works fine in all resolutions.
How to set it? -
In mainwindow, you can do
setFixedSize(1600, 900);
or
resize(1600, 900);depending on what you want.
If you set fixed size, then user with a screen of 1366x768
might not be not be able to use your app.