Skip to content
  • 0 Votes
    2 Posts
    405 Views
    C

    @Hai-Anh-Luu Welcome to the forum.

    Until the widget is displayed its size, and the size of any child widget in a layout, is unknown. In the widget class constructor^^ the widget is not yet shown so you get either the size hint from the widget concerned or some other value.

    ^^ That is when executing this line window = NewGrid()

    One way to see the size that is initially allocated is to do so in a slot connected to a zero-length (or very short) single-shot QTimer. This will fire when the event loop is reached, after the UI is shown. That is when app.exec() is running.

  • 0 Votes
    4 Posts
    991 Views
    EmrecpE

    @Chris-Kawa This worked, thank you very much!

  • 0 Votes
    5 Posts
    736 Views
    cerrC

    @nagesh Haha :boom: I knew it was something along these lines:
    "select combo box and expand horizontally in right direction it should occupy the
    empty space right to it"
    Shame on me and awesome! Thank you very much! lol
    I never asked that question, right? :D

  • 0 Votes
    1 Posts
    458 Views
    No one has replied
  • QGridLayout setRowStretch

    Unsolved General and Desktop
    2
    0 Votes
    2 Posts
    506 Views
    YunusY

    @GrahamLa hi. your problem is not clear to me. But when I run into a problem about QGridLayout I just check the qt calculator example
    ( https://doc.qt.io/qt-5/qtwidgets-widgets-calculator-example.html). it is very helpful to me. I think its better to share the whole code and please be more clear.

  • 0 Votes
    2 Posts
    5k Views
    P

    @Agricola

    Hi.
    If you look for ideal elements fit, like in form in QTCreator, You don't have to use Layout.
    Just put widgets on place, make it ALL proportional etc.
    include class I put below, I put example too at the end
    It works like a charm, if you will have to use QLayouts, make them MaxMin constraint, but results may be strange. When you use it, better forget about layouts ;)

    #ifndef GEOFIT_H #define GEOFIT_H #include <QWidget> #include <QApplication> #include <QWidgetList> #include <QScreen> #include <QDebug> class geofit : public QObject { Q_OBJECT public: explicit geofit(QObject* parent=0); virtual ~geofit(); QString orientation(); QWidget* widget; void widgetsResizer(QWidget*); bool fixed; QScreen* primary_screen=QApplication::primaryScreen(); #if defined(Q_OS_IOS) QSize viewport_size=QApplication::primaryScreen()->availableVirtualSize(); #else QSize viewport_size=QApplication::primaryScreen()->availableVirtualSize(); #endif int sW=viewport_size.width(); int sH=viewport_size.height(); }; #endif // GEOFIT_H

    SOURCE:

    #include "geofit.h" geofit::geofit(QObject* parent){ fixed=true; // if you want to have MinMax sizes setted } geofit::~geofit() { } QString geofit::orientation() { Qt::ScreenOrientation orientation=QApplication::primaryScreen()->orientation(); switch (orientation) { case Qt::PrimaryOrientation : return "Primary"; case Qt::LandscapeOrientation : return "Landscape"; case Qt::PortraitOrientation : return "Portrait"; case Qt::InvertedLandscapeOrientation : return "Inverted landscape"; case Qt::InvertedPortraitOrientation : return "Inverted portrait"; default: return "Unknown"; } } // INTELLIGENT RESIZE FORM TO FIT WITH KEEPING ASPECT RATIO void geofit::widgetsResizer(QWidget* w){ int x,y,xs,ys; w->geometry().getCoords(&x,&y,&xs,&ys); qDebug()<<viewport_size; qreal sFY=qreal(sH) / qreal(ys-y); qreal sFX=qreal(sW) / qreal(xs-x); QList<QWidget *> widgets = w->findChildren<QWidget *>(); for(int j = 0; j < widgets.count(); ++j){ widget=widgets.at(j); if(widget!=nullptr){ if(widget->objectName()=="centralwidget"){ widget->setFixedSize(sW,sH); widget->resize(sW,sH); // qDebug()<<"centr:"<<sW<<sH<<widget->geometry()<<widget->geometry()<<w->sizeHint(); // w->adjustSize(); // uncomment if document is partially displayed continue; } // DO NOT CHANGE ANYTHING IN NEXT 4 LINES x=widget->x()*(sFX*10000)/10000; // left - top corner X y=widget->y()*(sFY*10000)/10000; // Y xs=widget->width()*(sFX*10000)/10000; // width ys=widget->height()*(sFY*10000)/10000; // qDebug()<<widget->objectName()<<"!!"<<widget->geometry()<<x<<y<<xs<<ys;// height if(fixed){ widget->setFixedSize(xs,ys); } else qInfo()<<widget->objectName()<<" :: NO FIXED POLICY"; widget->setGeometry(x,y,xs,ys); } } // qDebug()<<"W1:"<<w->geometry()<<","<<w->sizeHint(); w->adjustSize(); // qDebug()<<"W2:"<<w->geometry()<<","<<w->sizeHint(); fixed=true; } EXAMPLE 1: .... ui->setupUi(this); geofit geo; geo.widgetsResizer(this); showFullScreen(); .... you can use it external. too: geofit geo; a=new a(this) b=new b(this) c=new c(this) geo(a); geo(b); geo(c);

    Good luck :)

  • QGridLayout

    Solved General and Desktop
    5
    0 Votes
    5 Posts
    738 Views
    G

    @GrahamLa
    The problem can be solved by setting row stretch

  • Layout problems

    Solved General and Desktop
    8
    1 Votes
    8 Posts
    2k Views
    mrjjM

    @GrahamLa
    Ok super. if you restrict widget, then layout will obey the limit.
    please mark as solved if your happy.

  • 0 Votes
    6 Posts
    3k Views
    SGaistS

    Why not implement my original suggestion ? Put a QLabel and your grid widget in a QStackedLayout and change to the label and back as needed ?

  • 0 Votes
    3 Posts
    2k Views
    NIXINN

    @mrjj I tried it but it didn't worked, however I found the solution for it.
    Break the Layout, arrange the widgets and then set the layout

  • 0 Votes
    2 Posts
    841 Views
    mrjjM

    Hi
    you could maybe use
    http://doc.qt.io/qt-5/qgraphicsitem.html#sceneBoundingRect
    and see if they are next to each other?

  • 0 Votes
    7 Posts
    3k Views
    B

    I think I was finally able to solve the problem.

    As the solution suggested by @hskoglund is Windows-specific, I decided to first investigate a bit deeper the other options presented by @J-Hilk

    It turned out that the Qt::WindowStaysOnTopHint flag was not set for our main window. I am now setting that flag in our main windows's constructor, and afterwards show it full screen. This seems to work.

    Thanks again for your suggestions!

  • 1 Votes
    7 Posts
    6k Views
    kshegunovK

    @Bart_Vandewoestyne

    I see you used a QVBoxLayout, but if I understand things correctly, it could've as well been a QHBoxLayout or QGridLayout because there's only one widget added?

    Yes of course, you can use whatever layout suits your needs. Also there is no restriction that you have to put one single widget in it, it can as easily accomodate many child widgets. QMainWindow is bit different in that respect, as it doesn't have a layout itself, but instead relies on a central widget (the client area) to do the laying out. I hope that clears things. :)

  • 0 Votes
    7 Posts
    8k Views
    R

    Thank you, I had a bit of a read around signal mappers and they seem like the perfect tool for what I need.

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    It's described here

  • 0 Votes
    4 Posts
    1k Views
    T

    @SGaist

    Sorry about that. This should be everything.

    Thanks!

  • 0 Votes
    2 Posts
    4k Views
    S

    Hi, this is old now but in case someone else finds this:
    I managed to solve this problem by using
    setSizeConstraint(QtWidgets.QLayout.SetNoConstraint)
    for a layout holding the QLineEdit widget. Actually it wasn't the layout holding the widget, but the layout holding that layout, so you may need to experiment to find out where you need to make this update (or just use SetNoConstraint for all your layouts)
    I hope this helps someone!

  • 0 Votes
    3 Posts
    1k Views
    H

    Did two thing.

    Using recommended code below, compilation Error appear ->"The program has unexpectedly finished"
    QImage myImage;
    myImage.load(":/file/rightp.png");
    myImage.scaled(1366,254, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

    How to scale stylesheet to 1/4 of mainwindow using below code

    MainWindow w;
    w.setStyleSheet("background-image:url(./file/left.png)");
    w.show();