All,
I need to create a relatively complex slider widget. It needs to be able to take multiple sliders per line, which would be able to move independently of each other.
I’ve created a notional version of it just putting the pixels on the screen with the .paintEvent() method of my custom widget, but of course the “blocks” on slider don’t move.
#include <QtGui>
#include "gnzprimtl.h"
#include <iostream>
GNZPrimTL::GNZPrimTL(QWidget *parent)
: QWidget(parent)
{
setWindowTitle(tr("Timeline Manager"));
}
void GNZPrimTL::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
//top left is (0,0)
//background and center stripe
QColor black = QColor(0,0,0);
QColor grey = QColor(127,127,127);
QColor blue = QColor(0,0,255);
QColor green = QColor(0,255,0);
painter.setBrush(black);
painter.drawRect(0, 0, width(), height());
painter.setBrush(grey);
painter.drawRoundedRect(width()*.025, (height()/2)*.85, width()*.95, height()*.2, 5.5, 5.5);
// block 1
painter.setBrush(green);
painter.drawRoundedRect(width()*.1, height()*.05, width()*.1, height()*.9, 5.5, 5.5);
// block 2
painter.setBrush(blue);
painter.drawRoundedRect(width()*.5, height()*.05, width()*.1, height()*.9, 5.5, 5.5);
return;
}
But of course the blocks don’t move in response to mouse events. I’m supposing I need to derive the background-and-frame class from some kind of container widget, and then instantiate the blocks as a child of the container.
Obviously not really sure where to start, though. Any help would be appreciated.
↧