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. KDGantt Chart Layout Help

KDGantt Chart Layout Help

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 341 Views
  • 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.
  • P Offline
    P Offline
    Phamy1289
    wrote on 28 Oct 2021, 12:32 last edited by
    #1

    My gantt chart looks a bit strange. The bars are not lined up with the information on the left and is there a way to have the columns on the left fill the rest of the layout?

    a3001e47-5ce2-469b-ae3c-91c8d582ff8b-image.png
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    Code:
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    Scheduler::Scheduler(QString title, QMainWindow *parent) : QDockWidget(title, parent)
    {
    setObjectName(title);
    mspInstance = this;

    //Set Schedular tab panel.
    setFeatures( QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
    setFocusPolicy(Qt::StrongFocus);
    
    QStandardItemModel *model = new QStandardItemModel;
    
    //Create item containers to add to the graph.
    QStandardItem *itemAlpha = new QStandardItem(QString("Alpha + B1"));
    QStandardItem *itemBravo = new QStandardItem(QString("Bravo + C2"));
    QStandardItem *itemCharlie = new QStandardItem(QString("Charlie + D1"));
    QStandardItem *itemDelta = new QStandardItem(QString("Delta + C3"));
    QStandardItem *itemBravo2 = new QStandardItem(QString("Bravo + India_1"));
    QStandardItem *itemHotel_1 = new QStandardItem(QString("Charlie + Hotel_Full"));
    
    //Fill the containers with the appropriate information and populate the graph.
    itemAlpha->appendRow(QList<QStandardItem*>()
                     << new MyStandardItem(QString ("Alpha + B1"))   // Sets name.
                     << new MyStandardItem(KDGantt::TypeTask)   // Sets type of task.
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(00, 00, 00)), KDGantt::StartTimeRole) // Sets Start Date.
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(1, 00, 00)), KDGantt::EndTimeRole)  // Sets Close Date.
                     );
    
    model->appendRow(QList<QStandardItem*>()
                     << itemAlpha
                     << new MyStandardItem(KDGantt::TypeMulti));
    
    itemBravo->appendRow(QList<QStandardItem*>()
                     << new MyStandardItem(QString ("Bravo + C2"))
                     << new MyStandardItem(KDGantt::TypeTask)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(1, 00, 00)), KDGantt::StartTimeRole)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(2, 30, 00)), KDGantt::EndTimeRole)
                     );
    
    model->appendRow(QList<QStandardItem*>()
                     << itemBravo
                     << new MyStandardItem(KDGantt::TypeMulti)
                     );
    
    itemCharlie->appendRow(QList<QStandardItem*>()
                     << new MyStandardItem(QString ("Charlie + D1"))
                     << new MyStandardItem(KDGantt::TypeTask)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(1, 35, 00)), KDGantt::StartTimeRole)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(3, 00, 00)), KDGantt::EndTimeRole)
                     );
    
    model->appendRow(QList<QStandardItem*>()
                     << itemCharlie
                     << new MyStandardItem(KDGantt::TypeMulti)
                     );
    
    itemDelta->appendRow(QList<QStandardItem*>()
                     << new MyStandardItem(QString ("Delta + C3"))
                     << new MyStandardItem(KDGantt::TypeTask)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(0, 00, 00)), KDGantt::StartTimeRole)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(6, 35, 00)), KDGantt::EndTimeRole)
                     );
    
    model->appendRow(QList<QStandardItem*>()
                     << itemDelta
                     << new MyStandardItem(KDGantt::TypeMulti)
                     );
    
    itemBravo2->appendRow(QList<QStandardItem*>()
                     << new MyStandardItem(QString ("Bravo + India_1"))
                     << new MyStandardItem(KDGantt::TypeTask)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(5, 35, 00)), KDGantt::StartTimeRole)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(7, 30, 00)), KDGantt::EndTimeRole)
                     );
    
    model->appendRow(QList<QStandardItem*>()
                     << itemBravo2
                     << new MyStandardItem(KDGantt::TypeMulti)
                     );
    
    itemHotel_1->appendRow(QList<QStandardItem*>()
                     << new MyStandardItem(QString ("Charlie + Hotel_Full"))
                     << new MyStandardItem(KDGantt::TypeTask)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(0, 35, 00)), KDGantt::StartTimeRole)
                     << new MyStandardItem(QDateTime(QDate(2021, 10, 10), QTime(3, 35, 00)), KDGantt::EndTimeRole)
                     );
    
    model->appendRow(QList<QStandardItem*>()
                     << itemHotel_1
                     << new MyStandardItem(KDGantt::TypeMulti)
                     );
    
    
    // Set widget to fit docker widget appropriately.
    KDGantt::View *view = new KDGantt::View();
    view->setMaximumWidth(950);
    
    // Define graph header to a 24hour period
    KDGantt::DateTimeGrid *grid = new KDGantt::DateTimeGrid;
    
    grid->setUserDefinedUpperScale(new KDGantt::DateTimeScaleFormatter(KDGantt::DateTimeScaleFormatter::Hour,
                                   QString("hh"),
                                   Qt::AlignLeft));
    
    // "Removes" the lower header column of the graph.
    grid->setUserDefinedLowerScale(new KDGantt::DateTimeScaleFormatter(KDGantt::DateTimeScaleFormatter::Hour,
                                   QString()));
    
    
    //Set bar graph to display 24hour periods
    grid->setScale(KDGantt::DateTimeGrid::ScaleUserDefined);
    grid->setDayWidth(500);
    grid->setRowSeparators(true);
    
    // Have the bars become blue instead of green.
    QBrush myBrush(Qt::blue);
    view->graphicsView()->itemDelegate()->setDefaultBrush(KDGantt::TypeTask,
                                                          myBrush);
    view->setGrid(grid);
    view->setModel(model);
    
    // Make it so the user can't change the bars' position.
    view->graphicsView()->setReadOnly(true);
    
    
    setWidget(view);
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Oct 2021, 19:16 last edited by
      #2

      Hi,

      Since it's a QAbstractItemView, you can configure its horizontal header view and to either make the last column stretch or all of them.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Phamy1289
        wrote on 3 Nov 2021, 15:07 last edited by
        #3

        I found it. I had to get access to the left pane and then set the width. Thank you for the help!

        view->leftView()->setMaximumWidth(100);

        1 Reply Last reply
        0

        2/3

        28 Oct 2021, 19:16

        • Login

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