在QT框架中,开发者可以创建自定义的控件来满足特定需求,比如设计一个具有特色的进度条。在“QT 自己写的进度条控件(透明窗体)”这个项目中,作者实现了一个自定义的进度条,它包含了两种不同的样式,并且整个窗体实现了透明效果。这种自定义控件的实现对于提升用户界面的美观性和个性化有着重要作用。 我们要理解QT中的QProgressBar类。QProgressBar是QT提供的一种标准控件,用于显示任务的进度。默认情况下,它是一个带有填充条纹的矩形框,填充部分代表已完成的任务比例。然而,通过继承QProgressBar并重写其paintEvent()方法,我们可以定制进度条的外观,比如改变条纹样式、颜色、形状等。 在这个项目中,作者可能创建了一个新的类,继承自QProgressBar,并添加了两个不同的进度条样式。一种可能是经典样式,另一种可能是独特的设计,比如圆形进度条或者带有动画效果的进度条。这样的设计可以增加用户交互的趣味性,提高用户体验。 实现窗体透明的关键在于利用Qt的窗口 flags 和 paintEvent() 方法。在Windows系统下,可以设置Qt的WS_EX_LAYERED 窗口风格来实现透明效果。通过调用setWindowFlags() 函数添加此标志,并使用setOpacity() 设置窗口的不透明度,可以实现不同程度的透明。在paintEvent() 方法中,需要处理背景的透明度,使得控件在透明背景上正确显示。 在VC6.0环境下编译QT项目,需要配置好QT的开发环境,确保MFC库与QT库的兼容性。这通常涉及到设置预处理器定义、包含目录、库目录和附加依赖项等。在QT4.5.3版本下,尽管较旧,但仍能支持VC6.0的编译,但需要注意的是,较新的QT版本可能不再支持这个古老的IDE。 项目文件"简单的进度条"可能包含了实现这些功能的源代码,如头文件(.h)和源文件(.cpp),以及可能的资源文件(.rc)。通过阅读和分析这些文件,可以深入理解作者如何实现自定义进度条和透明窗体效果。 总结来说,这个项目展示了如何在QT中创建自定义控件以实现独特的进度条样式,以及如何利用Qt的特性实现窗体透明。这对于想要提升应用界面独特性的开发者来说是一个很好的学习案例,同时也提醒我们,即使在旧的开发环境中,也可以利用QT强大的功能来实现创新的设计。
2024-08-28 11:02:41 866KB 进度条控件
1
static控件动态透明显示的完美解决方案
2024-03-01 08:25:33 7KB VC++ static控件 透明显示
1
C# 透明控件可以当Label控件使用,也可以改成透明控件Panel。 如果不值8分,你啪我。
2023-03-13 21:33:56 134KB Label Panel 控件透明 C#控件
1
计算机软件-商业源码-窗口加入图片及控件透明例子.zip
2022-05-23 09:05:08 60KB 源码软件
易语言控件透明化模块,标签 超级链接等。
2022-03-24 22:08:23 50KB 易语言,模块,透明
1
原tab控件,仿360开关控件版权归原作者! VB控件背景透明代码来自:新浪 “玄雨清风”的博客 感谢以上两位源代码作者 链接:http://pan.baidu.com/s/1hrAEXqG 密码:nfhc '-----------------------以下是转自博客的控件透明源代码(可透明至父窗体或桌面)------------- '添加一个用户控件UserControl,代如下: Option Explicit '实现用户控件UserControl的"伪透明" Private Type POINTAPI X As Long Y As Long End Type Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const WM_ERASEBKGND = &H14 Private Const WM_PAINT = &HF Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Private m_BK As Boolean '复制控件在父窗口的背景 Private Sub CopyParentBackground(ByVal phWnd As Long, ByVal chWnd As Long, ByVal hDestDC As Long) Dim lpRect As RECT, lpPoint As POINTAPI, nWidth As Long, nHeight As Long Dim BitMap As Long, oldBitMap As Long, hDC As Long, memDC As Long Call GetWindowRect(phWnd, lpRect) 'Call GetClientRect(phWnd, lpRect) nWidth = lpRect.Right - lpRect.Left '获取控件的宽度 nHeight = lpRect.Bottom - lpRect.Top '获取控件的高度 hDC = GetDC(0) BitMap = CreateCompatibleBitmap(hDC, nWidth, nHeight) Call ReleaseDC(0, hDC) memDC = CreateCompatibleDC(0) oldBitMap = SelectObject(memDC, BitMap) Call SendMessage(phWnd, WM_ERASEBKGND, memDC, 0) Call SendMessage(phWnd, WM_PAINT, memDC, 0) '至此memDC上已经保存了父窗口的背景内容 '用户可以调用BitBlt(...)等函数拷贝memDC的内容到子窗口的某个区域, '这样就达到了透明效果; Call GetWindowRect(chWnd, lpRect) lpPoint.X = lpRect.Left lpPoint.Y = lpRect.Top Call ScreenToClient(phWnd, lpPoint) '获取控件在父窗口的左上角位置 Call BitBlt(hDestDC, 0, 0, nWidth, nHeight, memDC, lpPoint.X, lpPoint.Y, SRCCOPY) ''''''''''''''''''''''复制背景之后,在这里可以其他事情'''''''''''''''''''''''''''' UserControl.CurrentY = 10 UserControl.Print "透明用户控件" UserControl.Refresh ' Call SelectObject(memDC, oldBitMap) Call DeleteDC(memDC) Call DeleteObject(BitMap) End Sub '复制控件在屏幕的背景 Private Sub CopyScreenBackground(ByVal phWnd As Long, ByVal chWnd As Long, ByVal hDestDC As Long) Dim lpRect As RECT, nWidth As Long, nHeight As Long, hDC As Long Call GetWindowRect(chWnd, lpRect) nWidth = lpRect.Right - lpRect.Left '获取控件的宽度 nHeight = lpRect.Bottom - lpRect.Top '获取控件的高度 ShowWindow chWnd, 0 '隐藏 DoEvents hDC = GetDC(0) Call BitBlt(hDestDC, 0, 0, nWidth, nHeight, hDC, lpRect.Left, lpRect.Top, SRCCOPY) Call ReleaseDC(0, hDC) ShowWindow chWnd, 5 '显示 ''''''''''''''''''''''复制背景之后,在这里可以其他事情'''''''''''''''''''''''''''' UserControl.CurrentY = 10 UserControl.Print "透明用户控件" UserControl.Refresh End Sub Private Sub UserControl_Initialize() UserControl.ScaleMode = vbPixels End Sub Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) RaiseEvent MouseDown(Button, Shift, X, Y) End Sub Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) RaiseEvent MouseMove(Button, Shift, X, Y) End Sub Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) RaiseEvent MouseUp(Button, Shift, X, Y) CopyBKImage m_BK End Sub Private Sub UserControl_Resize() On Error Resume Next CopyBKImage m_BK End Sub Private Sub UserControl_Show() CopyBKImage m_BK End Sub Public Property Let CopyBKMode(ByVal bkm As Boolean) m_BK = bkm End Property Public Property Let BorderStyle(BStyle As Boolean) If BStyle = True Then UserControl.BorderStyle = 1 Else UserControl.BorderStyle = 0 End If End Property Public Sub Refresh() CopyBKImage m_BK UserControl.Refresh End Sub Private Sub CopyBKImage(Optional ByVal flag As Boolean = False) If flag = True Then CopyScreenBackground UserControl.Parent.hwnd, UserControl.hwnd, UserControl.hDC Else CopyParentBackground UserControl.Parent.hwnd, UserControl.hwnd, UserControl.hDC End If End Sub '''''''''''''''''''''''''''''''调用实例''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''Form1代码'''''''''''''''''''''''''''''' Option Explicit Dim LabX As Single, LabY As Single, IsMouseDownLab As Boolean Private Sub ctl1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) IsMouseDownLab = True LabX = X: LabY = Y End Sub Private Sub ctl1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If IsMouseDownLab = True Then '移动ctl1的位置 If Button = 1 Then ctl1.Move ctl1.Left + Me.ScaleX(X - LabX, 3, 3), ctl1.Top + ScaleX(Y - LabY, 3, 3) End If End Sub Private Sub ctl1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) IsMouseDownLab = False End Sub Private Sub Form_Load() Me.ScaleMode = vbPixels ctl1.CopyBKMode = True '复制控件在屏幕的背景 ctl2.CopyBKMode = False '默认值,复制控件在父窗口的背景 ctl2.BorderStyle = True '有边框 ctl1.BorderStyle = False '无边框 End Sub
2022-03-20 14:42:35 74KB 控件背景透明 控件透明 仿360开关
1
原理很简单,就是设置控件的透明度,直到透明度为0后再将控件设置为隐藏即可。动画的过程可以用两种方式来实现,第一是通过定时器,不断的设置控件的透明度,第二是通过QPropertyAnimation来实现,当然,后者会更简单。那么该如何设置控件透明度呢,这里需要用到QGraphicsOpacityEffect类。更多文章请查看http://blog.csdn.net/luoyayun361/
2022-01-09 18:32:30 5KB Qt 控件透明
1
C++ Builder TPanel控件透明源代码,根据http://blog.csdn.net/cczlp/article/details/2542886整理。
2021-12-29 18:02:16 5KB BCB TPanel 控件透明
1
代码实现了MiniGUI的模拟触摸屏,按键切换图片,控件透明,适合新手欢迎下载,评论,讨论。
2021-12-02 21:43:00 9KB MiniGUI源码
1
为公司开发的静态控件,解决了所有的透明显示问题 1.动态刷新,文字重叠问题 2.父窗口放大之后,背景不对问题 3.频繁刷新闪动问题。 csdn有个帖子几十页也没解决,足见开发的难度之高。
2021-10-11 21:02:31 4KB CStatic 静态控件 透明 文字重叠
1