1.使用代碼設置漸變
QLinearGradient linearGrad(QPointF(0, 0), QPointF(200, 200));linearGrad.setColorAt(0, Qt::blue);linearGrad.setColorAt(1, Qt::white);linearGrad.setCoordinateMode(QGradient::StretchToDeviceMode);QBrush brush(linearGrad);item1->setBackground(brush);
2.QPixmap圖片的縮放
Qsize picSize(600,400);//將pixmap縮放成picSize大小然后保存在scaledPixmap中按比例縮放:QPixmap scaledPixmap = pixmap.scaled(picSize, Qt::KeepAspectRatio);不按照比例縮放QPixmap scaledPixmap = pixmap.scaled(picSize);
3.設置窗口不在任務欄顯示并置頂
setWindowFlags(Qt::Tool | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
4.QLineEdit去掉右鍵菜單
_ui->_passwordEdit->setContextMenuPolicy(Qt::NoContextMenu);//去掉右鍵菜單
5.去除QString中的空格
QString str = " lots\t of\nwhitespace\r\n "; str = str.trimmed(); // str == "lots\t of\nwhitespace" QString str = " lots\t of\nwhitespace\r\n "; str = str.simplified(); // str == "lots of whitespace";
6.QLabel實現(xiàn)超鏈接
ui->_userWebConnect->setOpenExternalLinks(true);ui->_userWebConnect->setText("<a href = \"http://zkuyun.com/\>顯示的內(nèi)容</a>");
7.QTreeView去掉父節(jié)點的下拉
treeView->setRootIsDecorated(false);// UI控件里,在右邊的設置屬性里找到 QTreeView那欄,將rootIs Decorated 復選框,不要勾選
聯(lián)系客服