In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Recently, in beautifying QT, I have been in a hurry to write pure code and beautify the interface. A lot of information has been searched on the Internet, but as the huge project has not yet been completed, first sort out the information on the Internet, there are some unused, save for later. Wait for my interface to be beautified and then po up.
/ * * reprint split line * /
Some experiences of Qt
This article is from: http://blog.csdn.net/lpt19832003/archive/2010/03/15/5381095.aspx
one。 The background is painted black and the foreground color is set to white.
Method 1, paltette mode, after testing, this method will not affect other controls, it is recommended to use
Click (here) to collapse or open
QPalette bgpal = palette ()
Bgpal.setColor (QPalette::Background, QColor (0,0,0,255))
/ / bgpal.setColor (QPalette::Background, Qt::transparent)
Bgpal.setColor (QPalette::Foreground, QColor (255255255255); setPalette (bgpal)
Method 2. Stylesheet method
The way to affect child controls is:
Click (here) to collapse or open
SetStyleSheet ("background-color: rgb; color: rgb (255255255);")
The method that does not affect child controls is:
Click (here) to collapse or open
SetStyleSheet ("venus--TitleBar {background-color: rgb; color: rgb (255255255);}")
Or
Click (here) to collapse or open
This- > setObjectName ("pw"); / / set the object sentence, which is equivalent to id in css
This- > setStyleSheet ("# pw {border-p_w_picpath: url (: / new/prefix1/Pic/54.png);}"); / / sets the background color of the id corresponding element
two。 The fillet control uses stylesheet mode
Click (here) to collapse or open
SetStyleSheet ("border:2px groove gray;border-radius:10px;padding:2px 4px;")
three。 Fillet window
Click (here) to collapse or open
RoundRectWin::RoundRectWin ()
{
QPalette p = palette ()
QPixmap img ("roundrect.png")
QBitmap mask ("roundrect_mask.png")
P.setBrush (QPalette::Window, QBrush (img))
SetPalette (p)
SetMask (mask)
Resize (img.size ())
/ / setWindowFlags (Qt::FramelessWindowHint); / / this sentence removes the title bar} Note: the extra part of the picture of mask is set to white.
}
four。 Translucent window
1. The window is overall transparent, but the controls on the form are opaque. By setting the background color of the form, the background color is set to fully transparent.
Click (here) to collapse or open
QPalette pal = palette ()
Pal.setColor (QPalette::Background, QColor (0x00.0xff.0x00.0x00))
SetPalette (pal)
Note: the title bar of the form is opaque, the controls on the client area of the form are opaque, the QLabel control is only a word display, and the background color of the control is transparent; the client area of the form is completely transparent.
In addition, the methods seen on the Internet:
Click (here) to collapse or open
SetAttribute (Qt::WA_TranslucentBackground, true)
The result of the experiment is similar to the method above, but sometimes the form is filled with mottled spots and the reason is not found.
two。 The window and its controls are translucent:
Click (here) to collapse or open
SetWindowOpacity (0.7)
Experimental effect: windows and controls are translucent. Be careful not to setWindowFlags (Qt::FramelessWindowHint); otherwise it won't work.
3. The window is opaque as a whole and partially transparent:
Use Clear mode to draw in the Paint event.
Click (here) to collapse or open
Void TestWindow::paintEvent (QPaintEvent*)
{
QPainter p (this)
P.setCompositionMode (QPainter::CompositionMode_Clear)
P.fillRect (10,10,300,300, Qt::SolidPattern)
}
Experimental effect: the drawing area is completely transparent. If the drawing area has a control, it does not affect the control.
The above experiments are all based on the Qte test of Directfb. The effect will be slightly different under Linux and Windows.
For example, in the third experiment under Windows, the drawing area is a black hole. If the Window itself is semi-transparent, it is the content under the Window plus the semi-transparent effect, not the full transparent effect.
five。 Control the alpha of QPixmap
Click (here) to collapse or open
QPixmap temp (pixmapTop.size ()); temp.fill (Qt::transparent)
QPainter p (& temp)
P.setCompositionMode (QPainter::CompositionMode_Source)
P.drawPixmap (0,0, pixmapTop)
P.setCompositionMode (QPainter::CompositionMode_DestinationIn)
P.fillRect (temp.rect (), QColor (0,0,0, alpha)); / /-- lable displays foreground images ui- > label- > setScaledContents (true)
Ui- > label- > setPixmap (temp)
six。 Boundary of layout
Click (here) to collapse or open
Layout- > setMargin (0)
Finally got the translucency of qt.
This article is from: http://hi.baidu.com/sszllx/blog/item/ab833a59ea98622f2934f001.html
Click (here) to collapse or open
QFrame * frame = new QFrame ()
QPixmap grabPixmap = QPixmap::grabWindow (frame- > winId (), 20,0,100,100)
Frame- > setGeometry (20,20,100,100)
Frame- > hide ()
QPixmap pixmap = Resource::loadPixmap ("qpelogo")
QImage p_w_picpath = pixmap.convertToImage ()
/ / p_w_picpath.convertDepth (32)
P_w_picpath.setAlphaBuffer (true)
QImage bgImage = grabPixmap.convertToImage ()
/ / bgImage.convertDepth (32)
BgImage.setAlphaBuffer (true)
Double k = 0.5
QRgb * rgbpos1 = p_w_picpath.colorTable ()
QRgb * rgbpos2 = bgImage.colorTable ()
For (int y = 0; y rect ()
QPainterPath path
/ / counterclockwise
Path.moveTo (arcR, 0)
Path.arcTo (0,0, arcR * 2, arcR * 2,90.0f, 90.0f)
Path.lineTo (0, rect.height ())
Path.lineTo (rect.width (), rect.height ())
Path.lineTo (rect.width (), arcR)
Path.arcTo (rect.width ()-arcR * 2,0, arcR * 2, arcR * 2,0.0f, 90.0f)
Path.lineTo (arcR, 0)
P.drawPath (path)
P.fillPath (path, QBrush (Qt::Red)); / / arm and windows platforms without this line of code will display a transparent, empty box
SetMask (bmp)
two。
In the constructor
Click (here) to collapse or open
SetAttribute (Qt::WA_TranslucentBackground, true)
SetWindowFlags (Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint
| | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint) |
Overload paintEvent
Click (here) to collapse or open
QPainter p (this)
P.drawRoundedRect (0,0, width ()-1, height ()-1,20,20)
3. Background picture
Click (here) to collapse or open
QPixmap pixmap (": / p_w_picpaths/*.png")
SetMask (pixmap.mask ())
QPalette palette
Palette.setBrush (QPalette::Background, QBrush (pixmap))
SetPalette (palette)
Resize (pixmap.size ())
SetMask (pixmap.mask ())
The same setMask (); is strangely different on three different platforms.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.