Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTimeEdit - c++

QTimeEdit - c++

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 336 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jakubd
    wrote on last edited by
    #1

    Hi, have been having trouble with the QTimeEdit widget recently. I wanted to create a pop-up window with a time choice and a save edit. Unfortunately after creating something I cannot edit it through any keyboard input. The only thing I can do is change the hour through up/down buttons in the widget. Unfortunately, I cant even access the minute's part of the widget. Here is the code used. I would really appreciate help, cant seem to figure it out on my own :)

        QWidget* popUp = new QWidget(this, Qt::Popup);
        popUp->setWindowModality(Qt::WindowModal);
        QRect rect = QStyle::alignedRect(layoutDirection(), Qt::AlignBottom, QSize(width()/4, height()/6), geometry());
        popUp->setGeometry(rect);
    
        QVBoxLayout* layout = new QVBoxLayout(popUp);
        QTimeEdit* timeChoice = new QTimeEdit();
        QTime* maxTime = new QTime();
       
        timeChoice->activateWindow();
        QPushButton *button1 = new QPushButton("SAVE");
    
        layout->addWidget(timeChoice);
        layout->addWidget(button1);
        
        popUp->show();
    
    artwawA 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      It may not matter, but then again, it might. timeChoice has no owner until you add it to the layout, and I can see that as problematic if you try to activate it beforehand.

      If you meet the AI on the road, kill it.

      1 Reply Last reply
      1
      • J jakubd

        Hi, have been having trouble with the QTimeEdit widget recently. I wanted to create a pop-up window with a time choice and a save edit. Unfortunately after creating something I cannot edit it through any keyboard input. The only thing I can do is change the hour through up/down buttons in the widget. Unfortunately, I cant even access the minute's part of the widget. Here is the code used. I would really appreciate help, cant seem to figure it out on my own :)

            QWidget* popUp = new QWidget(this, Qt::Popup);
            popUp->setWindowModality(Qt::WindowModal);
            QRect rect = QStyle::alignedRect(layoutDirection(), Qt::AlignBottom, QSize(width()/4, height()/6), geometry());
            popUp->setGeometry(rect);
        
            QVBoxLayout* layout = new QVBoxLayout(popUp);
            QTimeEdit* timeChoice = new QTimeEdit();
            QTime* maxTime = new QTime();
           
            timeChoice->activateWindow();
            QPushButton *button1 = new QPushButton("SAVE");
        
            layout->addWidget(timeChoice);
            layout->addWidget(button1);
            
            popUp->show();
        
        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @jakubd Hi
        I've rebuilt your example (macOS, Qt 6.9.1) as follows: fresh project, empty form with a button, single slot for a button. Here's mainwindow.cpp:

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QTime>
        #include <QVBoxLayout>
        #include <QTimeEdit>
        #include <QStyle>
        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
            connect(ui->pushButton,&QPushButton::clicked,this,&MainWindow::btnClicked);
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        void MainWindow::btnClicked() {
            QWidget* popUp = new QWidget(this, Qt::Popup);
                popUp->setWindowModality(Qt::WindowModal);
                QRect rect = QStyle::alignedRect(layoutDirection(), Qt::AlignBottom, QSize(width()/4, height()/6), geometry());
                popUp->setGeometry(rect);
        
                QVBoxLayout* layout = new QVBoxLayout(popUp);
                QTimeEdit* timeChoice = new QTimeEdit();
                QTime* maxTime = new QTime();
        
                timeChoice->activateWindow();
                QPushButton *button1 = new QPushButton("SAVE");
        
                layout->addWidget(timeChoice);
                layout->addWidget(button1);
        
                popUp->show();
        }
        

        It works as it should. You can't use keys in the beginning, when the form is shown since there is no focus on the QTimeEdit. Have you tried to press the tab key once? It'll put focus on the first available widget in the queue... Which happens to be what you want. Then you can use the keys.

        The remedy: in this case simple timeChoice->grabKeyboard(); would suffice but that's rather greedy option, perhaps you should examine the tab order of the modal dialog? Set the default (first) widget?

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved