qt控件被遮住的问题

jokers1990 2014-12-30 11:12:21
我在QDialog上定义了两个控件,一个QPushButton,一个QLabel,用setGeometry给它们设置好位置,然后我定义一个槽与QPushButton对象的click()信号连接,按一下QPushButton,将高度放大,然后发现它会被下面的QLabel遮住,除非将new QLabel 放在new QPushButton之前,请问下怎么解决这个问题啊???

class CMyDialog : public QDialog
{
Q_OBJECT
public:
CMyDialog(QWidget *parent);
private slots:
void ResizeFun();
private:
QPushButton *btn;
QLabel *lab;
}

CMyDialog:CMyDialog(QWidget *parent)
:QDialog(parent)
{
btn = new QPushButton(this);
lab = new QLabel(this);
btn->setGeometry(0, 0, 100, 50);
lab->setGeometry(0, 70, 100, 50);
connect(btn, SIGNAL(clicked()), this, SLOT(ResizeFun()));
}

void CMyDialog::ResizeFun()
{
btn->resize(btn->geometry().width(), btn->geometry(),height()*2);
}
...全文
1291 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jokers1990 2014-12-30
  • 打赏
  • 举报
回复 1
引用 1 楼 dbzhang800 的回复:
打开QWidget的手册,看 stackUnder() , raise() ,lower()
谢谢啦~用了raise就可以了~看来还是得仔细看手册呀~
l4kangaxx 2014-12-30
  • 打赏
  • 举报
回复
Raises this widget to the top of the parent widget's stack. After this call the widget will be visually in front of any overlapping sibling widgets. Note: When using activateWindow(), you can call this function to ensure that the window is stacked on top. See also lower() and stackUnder(). 想显示谁就调用谁的raise
dbzhang800 2014-12-30
  • 打赏
  • 举报
回复
打开QWidget的手册,看 stackUnder() , raise() ,lower()

16,199

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧