当前位置: 代码迷 >> QT开发 >> qt控件被遮住的有关问题
  详细解决方案

qt控件被遮住的有关问题

热度:260   发布时间:2016-04-25 03:04:31.0
qt控件被遮住的问题
本帖最后由 hx1984617 于 2014-12-30 11:13:34 编辑
我在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);
}

------解决思路----------------------
打开QWidget的手册,看  stackUnder() , raise() ,lower()
------解决思路----------------------
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
  相关解决方案