Qt:QTabWidget 亦凉 2022-05-12 11:50 231阅读 0赞 # 入门 # 1、新建QTGUI应用,基类选择QWidget,取消创建界面。添加资源文件 2、构造函数中 ![70][] #include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { QTabWidget *tab = new QTabWidget(this); QWidget *browser_tab = new QWidget; QWidget *users_tab = new QWidget; tab->addTab(browser_tab, QIcon(":resources/browser.png"), "Browser"); tab->addTab(users_tab, QIcon(":resources/users.png"), "Users"); tab->setGeometry(20, 20, 300, 250); QString btn_str[3] = {"Button 1", "Button 2", "Button 3"}; QPushButton *btn[3]; int ypos = 30; for(int i = 0 ; i < 3 ; i++) { btn[i] = new QPushButton(btn_str[i], browser_tab); btn[i]->setGeometry(10, ypos, 100, 40); ypos += 50; } connect(tab, SIGNAL(currentChanged(int)), this, SLOT(currentTab(int))); } void Widget::currentTab(int index) { qDebug("Current Tab : %d", index); } Widget::~Widget() { } ![效果][70 1] # UI设计 # ## 添加容器 ## ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poaXpoZW5nZ3Vhbg_size_16_color_FFFFFF_t_70][] ## 添加页面 ## ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poaXpoZW5nZ3Vhbg_size_16_color_FFFFFF_t_70 1][] ![20210225091214278.png][] ## 修改页面名 ## ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poaXpoZW5nZ3Vhbg_size_16_color_FFFFFF_t_70 2][] [70]: /images/20220512/cedba8acdd4f4282a073a1fc68c72dca.png [70 1]: /images/20220512/91b55d2b9c734615abfaa9cbf5be4646.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poaXpoZW5nZ3Vhbg_size_16_color_FFFFFF_t_70]: /images/20220512/14b742b0ccc14114a9a278da365ba9de.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poaXpoZW5nZ3Vhbg_size_16_color_FFFFFF_t_70 1]: /images/20220512/82af39eafadb40a196118fa6b912ed79.png [20210225091214278.png]: /images/20220512/3b90cd746d4c4b5c8d2b75de2ce169d6.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poaXpoZW5nZ3Vhbg_size_16_color_FFFFFF_t_70 2]: /images/20220512/ae4a79d0474545d3b21246d9a402b7be.png
还没有评论,来说两句吧...