Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

strange sizing behavior between QWidget and QMainWindow

$
0
0
I have noticed a strange widget sizing behavior between QWidget and QMainWindow. At first I’ve been using a QWidget to create my application window. Then I switched to QMainWindow because I wanted to use the menubar and other related stuff. In the application I only had 2 test widgets, a QPushButton and a QSlider, which had set only the minimum widget size (not the maximum). The result was kind of unexpected; the QMainWindow window was creating the widgets with a larger size than the QWidget window. I’ll attach here an image. As you can see there’s a lot of difference on the slider, while the PushButton seems to keep the minimum size. So, I’d like to ask you, is that some default behavior of QMainWindow? As long as it derives from the QWidget class, shouldn’t they behave the same? Anyway, setting a maximum widget size too keeps the slider at the specified size. EDIT sorry, I forgot to post the code: #include <QApplication> #include <QtWidgets> #include <dwmapi.h> #pragma comment(lib,"dwmapi.lib")   int main(int argc, char *argv[]) {     QApplication app(argc, argv);     QWidget win;     //QMainWindow win;     win.setAttribute(Qt::WA_TranslucentBackground);       MARGINS m = {-1};     DwmExtendFrameIntoClientArea((HWND)win.winId(), &m);       QSlider slider(&win);     slider.setFocusPolicy(Qt::StrongFocus);     slider.setTickPosition(QSlider::TicksBothSides);     slider.setMinimum(-10);     slider.setMaximum(10);     slider.setTickInterval(5);     slider.setSingleStep(1);     slider.setMinimumSize(40,150);     //slider.setMaximumSize(40,150);     slider.show();       QPushButton but(&win);     but.setMinimumSize(100,50);     //but.setMaximumSize(100,50);     but.show();       win.setMinimumSize(320,240);     win.show();       return app.exec(); }

Viewing all articles
Browse latest Browse all 13965

Latest Images

Trending Articles



Latest Images