在qt窗口中添加滚动条? [英] add scrollbar in qt window?

查看:482
本文介绍了在qt窗口中添加滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在,然后将所有其中的小部件(按钮等).不要忘记将滚动区域布置到整个主窗口.

更确切地说,层次结构是这样的:

 主窗口中央小部件(具有布局)滚动区域滚动区域小部件(带有布局,如果您在设计器中,则具有布局滚动区域)您的容器小部件(也应布局)您的按钮,布局等... 

((具有布局) =用布局对小部件进行布局,但是布局的类型无关紧要,因为只需要布局一个小部件).

您的容器窗口小部件应根据需要进行布局,分隔符可能很有用.

i have been learning qt from video tutorials here. i have completed 35 videos. So i wanted to create a sample application just to understand qt. i am using the latest version of qt creator.

i added some push-buttons & deleted the menu bar & tool bar in main window.

after running i found that if i resize the window scroll-bars don't appear.

i don't want the push-buttons to resize or move. i am fine with them becoming invisible but i want the scroll-bars so that the user can scroll to the invisible parts. i added a scroll area widget but it doesn't work. i did some coding by searching on internet but that didn't work either. when i increase the size of scroll area upto the window size; after running the window appears blank. maybe the push-buttons go 'below' the scroll-area. how do i change which object should be on 'top'?

also since i am just a beginner, i don't know whats the best approach in designing using qt. should i just put the required widgets using designer & then give their characteristics by coding? or should i do complete designing using designer? or should i abandon designer & do the complete coding? THANK YOU!

edit @Synxis, that didnt help much. I even used the secentralwidget(ui->scrollareacontentswidget); i tried deleting the centralwidget QWidget, but i cant. Any solution?

解决方案

A QWidget does not have scrollbars, you need to add a zone which will have scrollbars.

Just add a QScrollArea to your window, and put all the widgets in it (buttons, etc...). Don't forget to layout your scroll area to the whole main window.

More precisely, the hierarchy is something like that:

main window central widget (with a layout)
    scroll area
        scroll area widget (with a layout, layout scroll area if you're in the designer)
            your container widget (should be layouted also)
                your buttons, layouts, etc...

((with a layout) = layout the widget with a layout, but the type of the layout doesn't matter, since only one widget needs to be layouted).

Your container widget should be layouted as you want, spacers can be useful.

这篇关于在qt窗口中添加滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆