如题:登录框只占屏幕很小的一部分。登录后的主界面是全屏的。这样使登录框后面的背景就是主界面?当然看上去要像隔了一层纱,不能直接叠加。
从上到下顺序:登录框,一层纱,登录后主界面。
------解决方案--------------------
一层纱可以用一个QFrame来做,做一张半透明的图片(有部分镂空),找用过PS的应该都会,然后再QSS中设置该QFrame:
border-image: ...;
background: transparent;
这样纱就做出来了,至于三层的显示,慢慢调整咯
------解决方案--------------------
两层就够了,登录框和纱是一层,置顶。
后面是主界面。
------解决方案--------------------
建议为登录窗口单独建一个类,
ui类似这样:
- XML code
<?xml version="1.0" encoding="UTF-8"?><ui version="4.0"> <class>CTestForm</class> <widget class="QWidget" name="CTestForm"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>267</width> <height>416</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <property name="styleSheet"> <string notr="true"/> </property> <layout class="QGridLayout" name="gridLayout"> <property name="margin"> <number>0</number> </property> <property name="spacing"> <number>0</number> </property> <item row="0" column="0"> <widget class="QWidget" name="widget" native="true"> <property name="styleSheet"> <string notr="true">QWidget#widget{background-color: rgba(0, 0, 0, 200)}</string> </property> <widget class="QLineEdit" name="lineEdit"> <property name="geometry"> <rect> <x>70</x> <y>170</y> <width>113</width> <height>20</height> </rect> </property> </widget> <widget class="QPushButton" name="pushButton"> <property name="geometry"> <rect> <x>70</x> <y>220</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>PushButton</string> </property> </widget> </widget> </item> </layout> </widget> <resources/> <connections/></ui>
------解决方案--------------------
- XML code
<?xml version="1.0" encoding="UTF-8"?><ui version="4.0"> <class>CTestForm</class> <widget class="QWidget" name="CTestForm"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>267</width> <height>416</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <property name="styleSheet"> <string notr="true"/> </property> <layout class="QGridLayout" name="gridLayout"> <property name="margin"> <number>0</number> </property> <property name="spacing"> <number>0</number> </property> <item row="0" column="0"> <widget class="QWidget" name="widget" native="true"> <property name="styleSheet"> <string notr="true">QWidget#widget{background-color: rgba(0, 0, 0, 200)}</string> </property> <widget class="QLineEdit" name="lineEdit"> <property name="geometry"> <rect> <x>70</x> <y>170</y> <width>113</width> <height>20</height> </rect> </property> </widget> <widget class="QPushButton" name="pushButton"> <property name="geometry"> <rect> <x>70</x> <y>220</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>PushButton</string> </property> </widget> </widget> </item> </layout> </widget> <resources/> <connections/></ui>
------解决方案--------------------
先把你ui上的元素全部剪切下来,在窗口上画一个QWidget,然后调整布局让它占用整个窗口,之后把刚才剪下来的控件再全部拷到这个新的QWidget里。设置新的QWidget的样式为:QWidget#widget{background-color: rgba(0, 0, 0, 200)}
这里注意QWidget#widget是拾取器,后面的widget是要拾取的对象的名字,意思是设置只对这个对象起作用。
然后我在主窗口的函数中写这样的代码:
- C/C++ code
loginScreen *form = new loginScreen(this);form->show();
------解决方案--------------------
我这里给出你主界面里的代码,楼主仔细看,假定主界面叫MainForm
MainForm.h
- C/C++ code
class MainForm : public QWidget{...protected: void resizeEvent(QResizeEvent *event);private: loginScreen *m_login;...}