KDGantt Chart Layout Help
Solved
General and Desktop
-
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?
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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);
-
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.