Как можно реализовать следующий виджет в qt4.7.8

Можно с помощью Style Sheet переделать виджет Qdatetime в то что изображено на рисунки? введите сюда описание изображения


Ответы (2 шт):

Автор решения: S. Nick

Sorry, я любитель PyQt, в котором ваша задача может выглядеть примерно так:

import sys
from PyQt5.QtWidgets import QWidget, QLCDNumber, QVBoxLayout, QApplication
from PyQt5.QtCore import Qt, QTimer, QDateTime

class TestTimer(QWidget):
    def __init__(self, parent=None):
        super(TestTimer, self).__init__(parent)

        self.timeDisplay = QLCDNumber(digitCount=12) 
        self.timeDisplay.setSegmentStyle(QLCDNumber.Filled)
        self.timeDisplay.setMinimumSize(200, 100)

        vbox = QVBoxLayout(self)
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.addWidget(self.timeDisplay)   

        timer = QTimer(self)
        timer.timeout.connect(self.updtTime)        
        self.updtTime()
        timer.start(1000)

    def updtTime(self):
        currentTime = QDateTime.currentDateTime().toString('  hh:mm:ss  ')
        self.timeDisplay.display(currentTime)


styleSheet = """            
QWidget {
    border-image: url(table.png) 0 0 0 0 stretch stretch;
}
"""


if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setStyleSheet(styleSheet)
    w = TestTimer()
    w.setWindowTitle('Digital Clock')
    w.show()
    sys.exit(app.exec_())

введите сюда описание изображения

→ Ссылка
Автор решения: Alexander Chernin
class TestTimer : public QWidget {
    Q_OBJECT
public:
    TestTimer(QWidget* parent=nullptr):
        QWidget(parent) {

        timeDisplay = new QLCDNumber(12); 
        timeDisplay->setSegmentStyle(QLCDNumber::Filled);
        timeDisplay->setMinimumSize(200, 100);

        QVBoxLayout* vbox = new QVBoxLayout(this);
        vbox->setContentsMargins(0, 0, 0, 0);
        vbox->addWidget(timeDisplay); 

        QTimer* timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()), this, SLOT(updtTime()));
        updtTime();
        timer->start(1000);
    }

public slots:
    void updtTime() {
        QString currentTime = QDateTime::currentDateTime().toString('  hh:mm:ss  ');
        timeDisplay->display(currentTime);
    }
private:
    QLCDNumber* timeDisplay;
}

main.cpp:

QString styleSheet = "            
QWidget {
    border-image: url(table.png) 0 0 0 0 stretch stretch;
}
";

int main(int argc, int* argv[]) {
    QApplication app(argc, argv);
    app.setStyleSheet(styleSheet);    
    TestTimer w;
    w.setWindowTitle('Digital Clock');
    w.show();
    return app.exec();
}
→ Ссылка