Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

automatic Size policy when resizing window



  • hello,
    I'm searching from this morning how to do that ... I tried lot of things but never works.
    I would like to automaticaly resize policy when resizing window
    other thing, I tried to but the background in black ... but tried some tuto without success...
    If somebody can help me please:

    QWidget *widgetFondNoir = new QWidget();
    

    // widgetFondNoir->setStyleSheet("background-color: black");
    auto palette = widgetFondNoir->palette();
    palette.setColor(QPalette::Window, Qt::blue);
    widgetFondNoir->setPalette(palette);

    //Variables
    test=0;
    qTimeHeure.setHMS(0,0,00,000);
    qTimeHeureMeeting.setHMS(0,0,00,000);
    qTimeHeureRestante.setHMS(0,45,00,000);
    
    QLabel *labelHeure = new QLabel(this);
    QLabel *labelHeureRestant1 = new QLabel(this);
    QLabel *labelHeureRestant2 = new QLabel(this);
    QLabel *labelHeureRestant3 = new QLabel(this);
    
    labelHeure->setText(" HEURE : 19:25:54 ");
    labelHeure->setAlignment(Qt::AlignCenter);
    //labelHeure->setFont(QFont("Comic Sans MS", 14));
    
    labelHeureRestant1->setText(" TRACK WALK : 19:25:54 ");
    labelHeureRestant1->setAlignment(Qt::AlignCenter);
    //labelHeureRestant1->setFont(QFont("Comic Sans MS", 14));
    
    labelHeureRestant2->setText(" Mechanical_Fire_Up : 19:25:54 ");
    labelHeureRestant2->setAlignment(Qt::AlignCenter);
    //labelHeureRestant2->setFont(QFont("Comic Sans MS", 14));
    
    labelHeureRestant3->setText(" Test_Session_4 : 19:25:54 ");
    labelHeureRestant3->setAlignment(Qt::AlignCenter);
    //labelHeureRestant3->setFont(QFont("Comic Sans MS", 14));
    
    //Layout
    QGridLayout *layoutPrincipal = new QGridLayout(widgetFondNoir);
    QGridLayout *layoutMilieu = new QGridLayout(widgetFondNoir);
    
    layoutPrincipal->addWidget(boutonQuitter,12,10,1,3);
    layoutPrincipal->addWidget(boutonConnect,12,2,1,3);
    layoutMilieu->addWidget(labelHeure,1,3,2,4);
    layoutMilieu->addWidget(labelHeureRestant1,3,2,2,7);
    layoutMilieu->addWidget(labelHeureRestant2,6,2,2,7);
    layoutMilieu->addWidget(labelHeureRestant3,9,2,2,7);
    layoutPrincipal->addLayout(layoutMilieu,0,6);
    this->setLayout(layoutPrincipal);

  • Lifetime Qt Champion

    @SimonChoops said in automatic Size policy when resizing window:

    QGridLayout *layoutPrincipal = new QGridLayout(widgetFondNoir);
    QGridLayout *layoutMilieu = new QGridLayout(widgetFondNoir);

    Why do you create two layouts for the same widget?



  • @Christian-Ehrlicher
    Hello,

    This is to have a layout inside another one, because with just one when I resize it makes strange things.
    maybe it is not the go way to do but for the moment doesn't matter ^^ I would like the policy resized in the same time the window is resized...
    you now how to ?

    Thank you


  • Lifetime Qt Champion

    Hi,

    Passing a parent to a layout will apply that layout on the parent so if you want to have a layout in another layout, don't give a partent to that second layout and use the addLayout method of the main one.



  • @SGaist
    Hello,

    Ok I will do that but an idea for the main subject ? resize text in function of window's size ?


  • Lifetime Qt Champion

    @SimonChoops said in automatic Size policy when resizing window:

    resize text in function of window's size ?

    Where did you ask this question?
    You ant to automatically resize the text when the widget gets resized? You have to implement this by your own by e.g. overriding QWidget::resizeEvent()



  • @Christian-Ehrlicher
    Hello,
    on my first message :) and this is the name of the topic as well.

    I have to implement it really ? it's strange that is not possible basically.

    I don't have the level in QT to do this...

    anyway
    Thank you for your answer

    Simon



  • @SimonChoops
    You seemed to ask several different questions, it's not clear (to me, maybe others) just what it is you want.

    What resizing did you want/expect? When did "resize text" come into what you were asking? Resize in what way? I see you have lines commented out which had setFont() and a text size number, is that what you want/expect to change? So the font changes size when other things resize??


Log in to reply