ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); popMenu = new QMenu(ui->tableWidget); action = new QAction("connect",this); void MainWindow::on_tableWidget_customContextMenuRequested(const QPoint &pos) { popMenu->clear(); // popMenu for QTableWidget popMenu->addAction(action); // action for connect popMenu->exec(QCursor::pos()); }
滚动条位置设置
1 2 3
QTextEdit *edit = ui->textEdit; // example for QTextEdit QScrollBar *sb = edit->verticalScrollBar(); sb->setValue(sb->maximumHeight());
Qt正则
1 2 3 4 5
QString IPv4pattern("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"); QRegExp IPv4rx(IPv4pattern); if (IPv4rx.exactMatch("8.8.8.8")){ // example for IPv4 address check }